com.google.protobuf.ByteString

Here are the examples of the java api com.google.protobuf.ByteString taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2947 Examples 7

19 Source : PubSubPublisherUtil.java
with Apache License 2.0
from zhisheng17

/**
 * Publish messages with as payload a single integer.
 * The integers inside the messages start from 0 and increase by one for each message send.
 *
 * @param messagesCount message count
 */
void publish(int messagesCount) {
    Publisher publisher = null;
    try {
        publisher = Publisher.newBuilder(ProjectTopicName.of(projectName, topicName)).build();
        for (int i = 0; i < messagesCount; i++) {
            ByteString messageData = ByteString.copyFrom(BigInteger.valueOf(i).toByteArray());
            PubsubMessage message = PubsubMessage.newBuilder().setData(messageData).build();
            publisher.publish(message).get();
            System.out.println("Published message: " + i);
            Thread.sleep(100L);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (publisher != null) {
                publisher.shutdown();
            }
        } catch (Exception e) {
        }
    }
}

19 Source : EbftBlock.java
with Apache License 2.0
from yggdrash

@Override
public JsonObject getConsensusMessagesJsonObject() {
    JsonArray consensusJsonArray = new JsonArray();
    for (ByteString consensus : consensusList) {
        consensusJsonArray.add(consensus.toString());
    }
    JsonObject consensusJsonObject = new JsonObject();
    consensusJsonObject.add("consensus", consensusJsonArray);
    return consensusJsonObject;
}

19 Source : EbftBlock.java
with Apache License 2.0
from yggdrash

@Override
public JsonObject toJsonObject() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("block", getBlock().toJsonObject());
    if (!consensusList.isEmpty()) {
        JsonArray consensusJsonArray = new JsonArray();
        for (ByteString consensus : consensusList) {
            consensusJsonArray.add(consensus.toString());
        }
        jsonObject.add("consensusList", consensusJsonArray);
    }
    return jsonObject;
}

19 Source : TxEncoder.java
with Apache License 2.0
from xuperchain

private void encode(ByteString bs) {
    if (!bs.isEmpty()) {
        encode(Base64.toBase64String(bs.toByteArray()));
    }
}

19 Source : Utils.java
with Apache License 2.0
from wso2

static String toString(ByteString byteString) {
    return gson.toJson(byteString);
}

19 Source : AttributesBag.java
with Apache License 2.0
from wso2

public void put(String key, ByteString value) {
    putAttribute(key, Utils.toString(value));
}

19 Source : TTSEngine.java
with MIT License
from widavies

byte[] tts(String text) throws Exception {
    try (TextToSpeechClient client = TextToSpeechClient.create()) {
        SynthesisInput input = SynthesisInput.newBuilder().setSsml(text).build();
        VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().setLanguageCode(VocalCord.getConfig().languageCode).setSsmlGender(VocalCord.getConfig().voiceGender).build();
        AudioConfig audioConfig = AudioConfig.newBuilder().setAudioEncoding(AudioEncoding.LINEAR16).setSampleRateHertz(48_000).build();
        SynthesizeSpeechResponse response = client.synthesizeSpeech(input, voice, audioConfig);
        ByteString audioContents = response.getAudioContent();
        byte[] pcm = audioContents.toByteArray();
        // Three things need to happen - big endian, stereo, pad to a multiple of 3840
        // Add a frame of silence at the beginning so that the sound doesn't clip weirdly
        byte[] converted = new byte[AUDIO_FRAME + pcm.length * 2 + (AUDIO_FRAME - pcm.length * 2 % AUDIO_FRAME)];
        // ensures converted is a multiple of AUDIO_FRAME
        for (int i = AUDIO_FRAME; i < pcm.length; i += 2) {
            short reversed = Short.reverseBytes((short) ((pcm[i] << 8) | (pcm[i + 1] & 0xFF)));
            byte low = (byte) (reversed >> 8);
            byte high = (byte) (reversed & 0x00FF);
            // reverse bytes and double to convert to stereo
            converted[i * 2] = low;
            converted[i * 2 + 1] = high;
            converted[i * 2 + 2] = low;
            converted[i * 2 + 3] = high;
        }
        return converted;
    }
}

19 Source : STTEngine.java
with MIT License
from widavies

private List<SpeechRecognitionResult> speechRecognition(byte[] pcm) {
    try (SpeechClient speech = SpeechClient.create()) {
        ByteString audioBytes = ByteString.copyFrom(pcm);
        // Configure request with local raw PCM speechRecognition
        RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(RecognitionConfig.AudioEncoding.LINEAR16).setLanguageCode("en-US").setSampleRateHertz(16000).build();
        RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(audioBytes).build();
        // Use blocking call to get speechRecognition transcript
        RecognizeResponse response = speech.recognize(config, audio);
        return response.getResultsList();
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Failed to run Google Cloud speech recognition. Err: " + e.getMessage());
    }
    return new ArrayList<>();
}

19 Source : ThetaSketch.java
with Apache License 2.0
from whylabs

public Union deserialize(ByteString data) {
    val sketch = Sketch.heapify(Memory.wrap(data.toByteArray()));
    val union = Union.builder().buildUnion();
    union.update(sketch);
    return union;
}

19 Source : FrequentStringsSketch.java
with Apache License 2.0
from whylabs

public ItemsSketch<String> deserialize(ByteString bytes) {
    val data = bytes.toByteArray();
    ItemsSketch<String> freqNumbers;
    if (data.length > 8) {
        return ItemsSketch.getInstance(Memory.wrap(data), ARRAY_OF_STRINGS_SER_DE);
    } else {
        // Create an empty sketch
        return create();
    }
}

19 Source : GrpcSegmentation.java
with MIT License
from vision4j

@Override()
public SegmentationResult segment(byte[] imageBytes) throws IOException {
    SimpleImageInfo simpleImageInfo = new SimpleImageInfo(imageBytes);
    ByteString imageData = ByteString.copyFrom(imageBytes);
    Image.Builder imageBuilder = Image.newBuilder();
    imageBuilder.setWidth(simpleImageInfo.getWidth());
    imageBuilder.setHeight(simpleImageInfo.getHeight());
    imageBuilder.setOriginalHeight(simpleImageInfo.getHeight());
    imageBuilder.setOriginalWidth(simpleImageInfo.getWidth());
    imageBuilder.setChannels(3);
    imageBuilder.setImageData(imageData);
    Image image = imageBuilder.build();
    SegmentationArray segmentationarray = segmentationStub.segment(image);
    return this.convert(segmentationarray);
}

19 Source : GrpcFaceDetection.java
with MIT License
from vision4j

private Image prepareGrpcBytes(byte[] image) throws IOException {
    SimpleImageInfo simpleImageInfo = new SimpleImageInfo(image);
    ByteString imageData = ByteString.copyFrom(image);
    Image.Builder imageBuilder = Image.newBuilder();
    imageBuilder.setWidth(simpleImageInfo.getWidth());
    imageBuilder.setHeight(simpleImageInfo.getHeight());
    imageBuilder.setChannels(3);
    imageBuilder.setImageData(imageData);
    return imageBuilder.build();
}

19 Source : MutisignOperationerGodicTest.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced MutisignOperationerGodicTest {

    final String updateName = Long.toString(System.currentTimeMillis());

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    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.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    Optional<ShieldAddressInfo> shieldAddressInfo;

    String shieldAddress;

    List<Note> shieldOutList = new ArrayList<>();

    Account firstAccount;

    ByteString replacedetAccountId1;

    ByteString replacedetAccountId2;

    Optional<ExchangeList> listExchange;

    Optional<Exchange> exchangeIdInfo;

    Integer exchangeId = 0;

    Integer exchangeRate = 10;

    Long firstTokenInitialBalance = 10000L;

    Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey1.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey2.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    ECKey ecKey3 = new ECKey(Utils.getRandom());

    byte[] mutisignAccountAddress = ecKey3.getAddress();

    String mutisignAccountKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    ECKey ecKey4 = new ECKey(Utils.getRandom());

    byte[] newAddress = ecKey4.getAddress();

    String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private String foundationZenTokenKey = Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey");

    byte[] foundationZenTokenAddress = PublicMethed.getFinalAddress(foundationZenTokenKey);

    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 costTokenAmount = 8 * zenTokenFee;

    private Long sendTokenAmount = 3 * zenTokenFee;

    /**
     * constructor.
     */
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        if (PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getCreateTime() == 0) {
            PublicMethed.sendcoin(foundationZenTokenAddress, 20480000000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            String name = "shieldToken";
            Long start = System.currentTimeMillis() + 20000;
            Long end = System.currentTimeMillis() + 10000000000L;
            Long totalSupply = 15000000000000001L;
            String description = "This replacedet issue is use for exchange transaction stress";
            String url = "This replacedet issue is use for exchange transaction stress";
            PublicMethed.createreplacedetIssue(foundationZenTokenAddress, name, totalSupply, 1, 1, start, end, 1, description, url, 1000L, 1000L, 1L, 1L, foundationZenTokenKey, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            Account getreplacedetIdFromThisAccount = PublicMethed.queryAccount(foundationZenTokenAddress, blockingStubFull);
            ByteString replacedetAccountId = getreplacedetIdFromThisAccount.getreplacedetIssuedID();
            logger.info("replacedetId:" + replacedetAccountId.toString());
        }
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(mutisignAccountAddress, 1000_000_000_000L, fromAddress, testKey002, blockingStubFull));
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = manager1Key;
        ownerKeyString[1] = manager2Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"" + operations + "\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        replacedert.replacedertTrue(PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, new String[] { mutisignAccountKey }));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true)
    public void test001MutiSignGodicAccountTypeTransaction() {
        replacedert.replacedertTrue(PublicMethedForMutiSign.setAccountId1(("" + System.currentTimeMillis()).getBytes(), mutisignAccountAddress, mutisignAccountKey, 2, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.createAccountWhtiPermissionId(mutisignAccountAddress, newAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.sendcoinWithPermissionId(newAddress, 100L, mutisignAccountAddress, 2, mutisignAccountKey, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceWithPermissionId(mutisignAccountAddress, 1000000L, 0, 2, mutisignAccountKey, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceGetEntropyWithPermissionId(mutisignAccountAddress, 1000000L, 0, 1, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceForReceiverWithPermissionId(mutisignAccountAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.unFreezeBalanceWithPermissionId(mutisignAccountAddress, mutisignAccountKey, 0, null, 2, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.unFreezeBalanceWithPermissionId(mutisignAccountAddress, mutisignAccountKey, 0, newAddress, 2, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.updateAccountWithPermissionId(mutisignAccountAddress, updateName.getBytes(), mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
    }

    @Test(enabled = true)
    public void test002MutiSignGodicContractTypeTransaction() {
        Long maxFeeLimit = 1000000000L;
        // String contractName = "StorageAndCpu" + Integer.toString(randNum);
        String filePath = "./src/test/resources/soliditycode/walletTestMutiSign004.sol";
        String contractName = "timeoutTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] contractAddress = PublicMethedForMutiSign.deployContractWithPermissionId(contractName, abi, code, "", maxFeeLimit, 0L, 100, maxFeeLimit, "0", 0L, null, mutisignAccountKey, mutisignAccountAddress, blockingStubFull, permissionKeyString, 2);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
        replacedert.replacedertTrue(smartContract.getAbi().toString() != null);
        String txid;
        String initParmes = "\"" + "930" + "\"";
        txid = PublicMethedForMutiSign.triggerContractWithPermissionId(contractAddress, "testUseCpu(uint256)", initParmes, false, 0, maxFeeLimit, "0", 0L, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, permissionKeyString, 2);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethedForMutiSign.updateSettingWithPermissionId(contractAddress, 50, mutisignAccountKey, mutisignAccountAddress, 2, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.updateEntropyLimitWithPermissionId(contractAddress, 50, mutisignAccountKey, mutisignAccountAddress, 2, blockingStubFull, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethedForMutiSign.clearContractAbi(contractAddress, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true)
    public void test003MutiSignGodicTokenTypeTransaction() {
        long now = System.currentTimeMillis();
        String name = "MutiSign001_" + Long.toString(now);
        long totalSupply = now;
        Long start = System.currentTimeMillis() + 5000;
        Long end = System.currentTimeMillis() + 1000000000;
        logger.info("try create replacedet issue");
        replacedert.replacedertTrue(PublicMethedForMutiSign.createreplacedetIssueWithpermissionId(mutisignAccountAddress, name, totalSupply, 1, 1, start, end, 1, description, url, 2000L, 2000L, 1L, 1L, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // replacedert.replacedertTrue(PublicMethedForMutiSign.unFreezereplacedet(mutisignAccountAddress,
        // mutisignAccountKey,2,ownerKeyString,blockingStubFull));
        Account getreplacedetIdFromOwnerAccount;
        getreplacedetIdFromOwnerAccount = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull);
        replacedetAccountId1 = getreplacedetIdFromOwnerAccount.getreplacedetIssuedID();
        replacedert.replacedertTrue(PublicMethedForMutiSign.transferreplacedetWithpermissionId(manager1Address, replacedetAccountId1.toByteArray(), 10, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethedForMutiSign.updatereplacedetWithPermissionId(mutisignAccountAddress, description.getBytes(), url.getBytes(), 100L, 100L, mutisignAccountKey, 2, blockingStubFull, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true)
    public void test004MutiSignGodicExchangeTypeTransaction() {
        ECKey ecKey22 = new ECKey(Utils.getRandom());
        byte[] secondExchange001Address = ecKey22.getAddress();
        String secondExchange001Key = ByteArray.toHexString(ecKey22.getPrivKeyBytes());
        Long secondTransferreplacedetToFirstAccountNum = 100000000L;
        long now = System.currentTimeMillis();
        String name2 = "exchange001_2_" + Long.toString(now);
        String name1 = "exchange001_1_" + Long.toString(now);
        final long totalSupply = 1000000001L;
        org.junit.replacedert.replacedertTrue(PublicMethed.sendcoin(secondExchange001Address, 10240000000L, fromAddress, testKey002, blockingStubFull));
        org.junit.replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 100000000000L, 0, 0, ByteString.copyFrom(secondExchange001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long start = System.currentTimeMillis() + 5000L;
        Long end = System.currentTimeMillis() + 5000000L;
        org.junit.replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(secondExchange001Address, name2, totalSupply, 1, 1, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, secondExchange001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        listExchange = PublicMethed.getExchangeList(blockingStubFull);
        exchangeId = listExchange.get().getExchangesCount();
        Account getreplacedetIdFromThisAccount;
        getreplacedetIdFromThisAccount = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull);
        replacedetAccountId1 = getreplacedetIdFromThisAccount.getreplacedetIssuedID();
        getreplacedetIdFromThisAccount = PublicMethed.queryAccount(secondExchange001Address, blockingStubFull);
        replacedetAccountId2 = getreplacedetIdFromThisAccount.getreplacedetIssuedID();
        firstAccount = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull);
        org.junit.replacedert.replacedertTrue(PublicMethed.transferreplacedet(mutisignAccountAddress, replacedetAccountId2.toByteArray(), secondTransferreplacedetToFirstAccountNum, secondExchange001Address, secondExchange001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        org.junit.replacedert.replacedertTrue(PublicMethedForMutiSign.exchangeCreate1(replacedetAccountId1.toByteArray(), firstTokenInitialBalance, replacedetAccountId2.toByteArray(), secondTokenInitialBalance, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        listExchange = PublicMethed.getExchangeList(blockingStubFull);
        exchangeId = listExchange.get().getExchangesCount();
        org.junit.replacedert.replacedertTrue(PublicMethedForMutiSign.injectExchange1(exchangeId, replacedetAccountId1.toByteArray(), 100, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        org.junit.replacedert.replacedertTrue(PublicMethedForMutiSign.exchangeWithdraw1(exchangeId, replacedetAccountId1.toByteArray(), 200, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        firstAccount = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull);
        org.junit.replacedert.replacedertTrue(PublicMethedForMutiSign.exchangeTransaction1(exchangeId, replacedetAccountId1.toByteArray(), 50, 1, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        firstAccount = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull);
        replacedert.replacedertTrue(PublicMethedForMutiSign.participatereplacedetIssueWithPermissionId(secondExchange001Address, replacedetAccountId2.toByteArray(), 1, mutisignAccountAddress, mutisignAccountKey, 2, blockingStubFull, ownerKeyString));
    }

    @Test(enabled = true)
    public void test005MutiSignGodicShieldTransaction() {
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(mutisignAccountAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        Args.setFullNodeAllowShieldedTransaction(true);
        shieldAddressInfo = PublicMethed.generateShieldAddress();
        shieldAddress = shieldAddressInfo.get().getAddress();
        logger.info("shieldAddress:" + shieldAddress);
        final Long beforereplacedetBalance = PublicMethed.getreplacedetIssueValue(mutisignAccountAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull);
        final Long beforeBalance = PublicMethed.queryAccount(mutisignAccountAddress, blockingStubFull).getBalance();
        final Long beforePhotonUsed = PublicMethed.getAccountResource(mutisignAccountAddress, blockingStubFull).getFreePhotonUsed();
        String memo = "aaaaaaa";
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, shieldAddress, "" + (sendTokenAmount - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethedForMutiSign.sendShieldCoin(mutisignAccountAddress, sendTokenAmount, null, null, shieldOutList, null, 0, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true)
    public void test006MutiSignGodicWitnessTransaction() {
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = manager1Key;
        ownerKeyString[1] = manager2Key;
        PublicMethed.printAddress(newKey);
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"" + operations + "\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        replacedert.replacedertTrue(PublicMethed.sendcoin(newAddress, 1000000_000_000L, fromAddress, testKey002, blockingStubFull));
        logger.info(accountPermissionJson);
        replacedert.replacedertTrue(PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, newAddress, newKey, blockingStubFull, new String[] { newKey }));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long now = System.currentTimeMillis();
        String url = "MutiSign001_" + Long.toString(now) + ".com";
        replacedert.replacedertTrue(PublicMethedForMutiSign.createWitness(url, newAddress, newKey, 2, permissionKeyString, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethedForMutiSign.updateWitness2(newAddress, "newWitness.com".getBytes(), newKey, 2, permissionKeyString, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String voteStr = Base58.encode58Check(newAddress);
        HashMap<String, String> smallVoteMap = new HashMap<String, String>();
        smallVoteMap.put(voteStr, "1");
        replacedert.replacedertTrue(PublicMethedForMutiSign.voteWitnessWithPermissionId(smallVoteMap, mutisignAccountAddress, mutisignAccountKey, blockingStubFull, 2, permissionKeyString));
    }

    @Test(enabled = true)
    public void test007MutiSignGodicProposalTypeTransaction() {
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        HashMap<Long, Long> proposalMap = new HashMap<Long, Long>();
        proposalMap.put(0L, 81000L);
        replacedert.replacedertTrue(PublicMethedForMutiSign.createProposalWithPermissionId(newAddress, newKey, proposalMap, 2, blockingStubFull, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // Get proposal list
        ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build());
        Optional<ProposalList> listProposals = Optional.ofNullable(proposalList);
        final Integer proposalId = listProposals.get().getProposalsCount();
        logger.info(Integer.toString(proposalId));
        replacedert.replacedertTrue(PublicMethedForMutiSign.approveProposalWithPermission(newAddress, newKey, proposalId, true, 2, blockingStubFull, permissionKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // Delete proposal list after approve
        replacedert.replacedertTrue(PublicMethedForMutiSign.deleteProposalWithPermissionId(newAddress, newKey, proposalId, 2, blockingStubFull, permissionKeyString));
    }

    @Test(enabled = true)
    public void test008MutiSignGodicWithdrawBanlanceTransaction() {
        long MaintenanceTimeInterval = -1L;
        ChainParameters chainParameters = blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build());
        Optional<ChainParameters> 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().equals("getMaintenanceTimeInterval")) {
                MaintenanceTimeInterval = getChainParameters.get().getChainParameter(i).getValue();
                break;
            }
        }
        try {
            Thread.sleep(MaintenanceTimeInterval);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        replacedert.replacedertTrue(PublicMethedForMutiSign.withdrawBalance(newAddress, newKey, 2, permissionKeyString, blockingStubFull));
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : TestMutiSignStress.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced TestMutiSignStress {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private final String witnessKey001 = Configuration.getByPath("testng.conf").getString("witness.key1");

    private final byte[] witnessAddress = PublicMethed.getFinalAddress(witnessKey001);

    ByteString replacedetAccountId1;

    String[] ownerKeyString = new String[1];

    String accountPermissionJson = "";

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, threadPoolSize = 30, invocationCount = 30)
    public void testMutiSignForAccount() {
        PublicMethed.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();
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, 9968981537400L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        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());
        permissionKeyString[1] = manager2Key;
        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\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
        // permissionKeyString[0] = ownerKey;
        String[] ownerKeyString1 = new String[3];
        ownerKeyString1[0] = ownerKey;
        ownerKeyString1[1] = manager1Key;
        ownerKeyString1[2] = manager2Key;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Integer i = 0;
        while (i++ <= 1000) {
            ecKey4 = new ECKey(Utils.getRandom());
            newAddress = ecKey4.getAddress();
            newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());
            PublicMethed.printAddress(newKey);
            PublicMethedForMutiSign.sendcoin(newAddress, 4000000L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.freezeBalance(ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.freezeBalanceGetEntropy(ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.freezeBalanceForReceiver(ownerAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), ownerKey, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, newAddress, blockingStubFull, ownerKeyString1);
            PublicMethedForMutiSign.updateAccount(ownerAddress, Long.toString(System.currentTimeMillis()).getBytes(), ownerKey, blockingStubFull, ownerKeyString1);
        }
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : SupportVisionLinkAutoTest.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced SupportVisionLinkAutoTest {

    private final String testKey002 = "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25";

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[1];

    String accountPermissionJson = "";

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey1.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey2.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    ECKey ecKey3 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey3.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    ECKey ecKey4 = new ECKey(Utils.getRandom());

    byte[] newAddress = ecKey4.getAddress();

    String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    // Mainnet fullnode
    private String fullnode = "47.252.19.181:50051";

    // dappchain fullnode
    // private String fullnode =       "47.252.7.241:50051";
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
    public void testMutiSignForAccount() {
        Integer i = 0;
        System.out.println("Start genterate address");
        while (i++ < 20) {
            ecKey1 = new ECKey(Utils.getRandom());
            manager1Address = ecKey1.getAddress();
            manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
            ecKey3 = new ECKey(Utils.getRandom());
            ownerAddress = ecKey3.getAddress();
            ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
            // PublicMethed.printAddress(ownerKey);
            PublicMethed.sendcoin(ownerAddress, 200000000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            permissionKeyString[0] = manager1Key;
            permissionKeyString[1] = ownerKey;
            ownerKeyString[0] = ownerKey;
            // ownerKeyString[1] = manager1Key;
            accountPermissionJson = "{\"owner_permission\":{\"type\":0," + "\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2," + "\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"" + "7fff1fc0033e0b00000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}" + "]}]}";
            // logger.info(accountPermissionJson);
            PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
            System.out.println("owner" + i + " --------------------------------------------------------");
            PublicMethed.printAddress(ownerKey);
            System.out.println("mutli sig address for owner " + i + " ----------------------------------");
            PublicMethed.printAddress(manager1Key);
            System.out.println("-------------------------------" + "-----------------------------------------");
        }
    }

    @Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
    public void test002CreateWitness() {
        Integer i = 0;
        System.out.println("Start genterate  witness address");
        while (i++ < 10) {
            ecKey3 = new ECKey(Utils.getRandom());
            ownerAddress = ecKey3.getAddress();
            ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
            // PublicMethed.printAddress(ownerKey);
            PublicMethed.sendcoin(ownerAddress, 50000000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            String createWitnessUrl = "IOS-UI-Witness-00" + i;
            byte[] createUrl = createWitnessUrl.getBytes();
            createWitness(ownerAddress, createUrl, ownerKey);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            System.out.println("witness " + i + " -----------------------------" + "---------------------------");
            PublicMethed.printAddress(ownerKey);
            System.out.println("witness url is : " + createWitnessUrl);
            System.out.println("-------------------------------------------" + "-----------------------------");
        }
    }

    @Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
    public void test03MutiSignForAccount() {
        HashMap<String, String> muti = new HashMap();
        muti.put("9a2ba173645be8d37a82084f984ba873fbcf817b589c62a59b3ba1494c3406e0", "cefba96470224724bde255f3402fca3d67b6c7c5d34deb7a8524c9482c58fe8b");
        muti.put("36f5430b4003f41ee8969421d9366ab1414e62111aec07a73d06eefcda8aad14", "3adcd73ad1fa03ce2fd4d29e29a7c96ef2f78bece85cba6e58997826682c4c1e");
        muti.put("4b47cf37528724dc8bc99188063f5aec9a7bc32aadfad5a96a9e9cccba7cede1", "948d856ebeb787aabd495fc13627f7442e7c1f21e9ed784f795e14f13cbebb94");
        muti.put("75d0856799cf2b2c807ed0eb5bb091bb943f2caed830add4b8df14c537f86e9a", "7fb13ad0b62d4ff116ebd3d901d458697902ce81a8fc30c20c60aba1ca6964ec");
        muti.put("327bf1b4a3193c2bebf239c1c5bda09a8d375251361ea9c7418aa2adf2d17b7e", "a8236968966db785ffe63d613174ee25e1baff03817b64db905c5940ed3dcc4b");
        muti.put("cf83d9494a9268fd3a75bd76bcfabaa7ec766e9084129a20e1823f81fbdca933", "1e53c948e949e39f60a3be2382382f9a50f88b658ea79c418ece1c5f9b169441");
        muti.put("19ff919e92462f07c7eced256d4cb588a66ac900d544d0d4d16ae49732de79cb", "166ddc2cd6379e7971e2c65d224594b709ebb59b3c6051c156214c299129f420");
        muti.put("7901db57a410a26d333b6d7fe4e054ddffbdc646f94ca03577bfd5e87120b9af", "89d9a47b37f5625e14082b575d5e657b21f6dae125125bee51fafd1e8cdf0804");
        muti.put("e3c7204d652a6fdcda05cbce061904d441dece7bf0a1778c1ddf0906aa36a279", "7d308998f829c0581447831003d994216a3a003ba00eef6a4e48e28b3178fbb3");
        muti.put("826fc86d572ba9de06f20963fcbfb44f4c397875bd4d7b36fdcb83476df33f05", "25aa122142a52ea8ba7bdf832c39a194d498774d4f675b8bcb17280c33990a08");
        muti.put("9705dd852465d04be349e94865142fc636d038138a4bfe8f94abc9b49f1dc14a", "0b675f14c1e06a6473c517dded162472ce2bb5c8934f198df1a791b75c30f983");
        muti.put("075f86d3d4053929714ddedb3e458467e6d494c3d4b0c71dafb63279de1beb89", "4880695a6e31f4f69d6f261eedfa5dcb5fc1b9194483658f77625ec4e6b2e493");
        muti.put("91ae6c8a1bff0b71f6f2b9de54d3b39502bcab906f980569109ab8425cb0bdc5", "90ef4adb0772ee49089784ccad234867a10395064749788b461cbe91265424fb");
        muti.put("9acb90c4d15c87dd2a1f322eddaabdde22cd78fe5eab371bfcf0c8be80bef8a8", "951f03193e1d7d4bff016da100b74f8ac220aabfd9c2841438ee758702c8e3f4");
        muti.put("f8eae7be0fac4e9fab40139e58b405f7e5d5b13a83220a6e4955ffaacbbe2a7d", "66692c0aaad6cfd349bdffbf3fdd688558a6c7a95ff67f249e0e80847167013a");
        muti.put("2e20c1a4b9a3a79696cbf0d03dedc39d8021657028fbf3dbc5da85ea61ad5dff", "ae7ecb7fba0d77d116a23f96a4dfecdef09741e363f0be12f99c86b3815d8fff");
        muti.put("e5e60c52f3b11ce0cfbc4e86d078ab53435ebc2422fd851614a25b5063ae7040", "42c575d8848809082c6872b2dcdb0e81d5f06ca120c636b90d0b062965ea0871");
        muti.put("fd4ee3a678a749c2049d5b1cba757648386c84ac2481be8de02069d41e4fb312", "ef2095532f572be8d021886780f7e508665ef40c1499273b91813ddc27d1354b");
        muti.put("297f6e034e9366691922ff5394810f724094bd0a07b4ca60f0f281ec71562094", "4ab67f1c42db0b63bafc0f33cf59575998c3259e96f5f89ea379dac4298d2bd7");
        int i = 1;
        for (HashMap.Entry entry : muti.entrySet()) {
            // entry.getKey().toString();
            // entry.getValue().toString();
            ownerKey = entry.getKey().toString();
            ownerAddress = PublicMethed.getFinalAddress(ownerKey);
            manager1Key = entry.getValue().toString();
            manager1Address = PublicMethed.getFinalAddress(manager1Key);
            // System.out.println("ownerKey:" + ownerKey);
            // System.out.println("manager1Key:" + manager1Key);
            // System.exit(1);
            PublicMethed.sendcoin(ownerAddress, 20000000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            permissionKeyString[0] = manager1Key;
            permissionKeyString[1] = ownerKey;
            ownerKeyString[0] = ownerKey;
            // ownerKeyString[1] = manager1Key;
            accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"" + "threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"" + "active\",\"threshold\":2," + "\"operations\":\"" + "7fff1fc0033e0b00000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}" + "]}]}";
            // logger.info(accountPermissionJson);
            PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
            System.out.println("owner " + i++ + " -----------------" + "---------------------------------------");
            PublicMethed.printAddress(ownerKey);
            System.out.println("mutli sig address for owner " + i++ + " ------------" + "----------------------");
            PublicMethed.printAddress(manager1Key);
            System.out.println("-----------------------------------" + "-------------------------------------");
        }
    }

    @Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
    public void test004CreateWitness() {
        String[] witnessKey = { "c74fb4d8101572041c6fab30e1602ba1ec8247e1ead19641fb985b3ed3a8261e", "25f98ac22c9fd02aa8a2ef354db0aa13ebc2a6c31377ea7e2b342f0d3898af0d", "939a2cec3768bd2d2834126c20d2b1c513e3711f085ce374f654a7b144aa409f", "39862f4dd51972ca22ce50b7b9e629043387000120c33bf263399ad9b334da1a", "79045aab0f3199ac456ce2039e809e6c942983ede0e3a398d571dedddb351348", "d50fe9c48e95289cde324ffeff095f8275f9ab07375e5e843167a0a54d3e1462", "61651f2b8a87e1ae0ced5e700807f2abb50e97fe7d3d3e6a8aa58f0a6b0149a6", "bb03d70e5187258ffb6cddb1becade5c1b2606b7ea84636b7dfaeef6216610a5", "25858c236634e353d018f310f61e077b78e1410766565ed56ff11ee7410dcf20", "ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046" };
        int i = 1;
        for (String ownerKey : witnessKey) {
            byte[] ownerAddress = PublicMethed.getFinalAddress(ownerKey);
            PublicMethed.sendcoin(ownerAddress, 20000000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            String createWitnessUrl = "IOS-UI-Witness-00" + i++;
            byte[] createUrl = createWitnessUrl.getBytes();
            createWitness(ownerAddress, createUrl, ownerKey);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
            PublicMethed.printAddress(ownerKey);
            System.out.println("witness url is : " + createWitnessUrl);
            System.out.println("---------------------------------------------------------------------");
        }
    }

    @Test(enabled = true, threadPoolSize = 1, invocationCount = 1)
    public void test005SendVrc20() {
        String[] witnessKey = { "TR8CyAPJFMjCvphCVuWeeVxBh5iTG7VWxe", "TMhGDU7NiXwckCW64PqAvWFuC2kR1WSF5J", "TDf3JZtjDeEqsFdPGp6vT9meG3JxMwmXwA", "TEtG9fnVi2qythiog6owPrg4sD9rwFBQBN", "TUvda1oqrNLbqDKhZDxDnrPhiDCdxem218", "TKEH31jJ2YQ3Bteh1ngjwdT8667ztyYPSp", "TAzrJHKa57nXnn3dZGFG87PDuWx12dY97s", "TWhc6AAh6BWRr3k5dV8iMvkp8ys7NHzXCk", "TSsaSxHnb3xLTop2A8LrDk1P896yiDeupe", "TMDs8oTj8mVnakqiVyDKdp2ruWPdFeDgbq", "TWv2FEsoPp5XKxujVHffoNwksgJSxvf3QG", "TGamEmt6U9ZUg9bFsMq7KT9bRa3uvkdtHM", "TXhQk442CCGLydh6cfyfqvM6yJanEGeQj1", "TKktQcbjXsXZDKPYLvUm8sxox2cT83g5rP", "TBQUhYhdQpMRksBGAbpbTWSiE7WkGgy3Km", "TALf34yjuLZjF1WQqCaUkf73X8WbhfiEyM", "TCGp3JAFM5vQZpsdNiKRTci7fVb7A2TPcu", "TBExF3mNvnhmEFgHW4TmYXXdhevRchnQyb", "TS8o6WcHroSnzWNt4AiserAuVkye5Msvcm", "TBtMRD79NkLyAvMkCTTj5VC5KZnz2Po2XZ" };
        int i = 1;
        for (String ownerKey : witnessKey) {
            String triggerString = "\"" + ownerKey + "\"" + ", 20000000000";
            System.out.println(triggerString);
            // dapp chain vrc20 tract TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7
            byte[] contractAddress = PublicMethed.decode58Check("TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7");
            // main chain TRC 20 contract TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71
            // byte[] contractAddress =  PublicMethed.decode58Check("TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71");
            PublicMethed.triggerContract(contractAddress, "transfer(address,uint256)", triggerString, false, 0, 1000000000, "0", 0, fromAddress, testKey002, blockingStubFull);
            PublicMethed.waitProduceNextBlock(blockingStubFull);
        }
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }

    /**
     * constructor.
     */
    public Boolean createWitness(byte[] owner, byte[] url, String priKey) {
        ECKey temKey = null;
        try {
            BigInteger priK = new BigInteger(priKey, 16);
            temKey = ECKey.fromPrivate(priK);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        final ECKey ecKey = temKey;
        WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract.newBuilder();
        builder.setOwnerAddress(ByteString.copyFrom(owner));
        builder.setUrl(ByteString.copyFrom(url));
        WitnessContract.WitnessCreateContract contract = builder.build();
        Protocol.Transaction transaction = blockingStubFull.createWitness(contract);
        if (transaction == null || transaction.getRawData().getContractCount() == 0) {
            return false;
        }
        transaction = PublicMethed.signTransaction(ecKey, transaction);
        GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction);
        if (response.getResult() == false) {
            return false;
        } else {
            return true;
        }
    }
}

19 Source : MutiSignStress.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced MutiSignStress {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private final String witnessKey001 = Configuration.getByPath("testng.conf").getString("witness.key1");

    private final byte[] witnessAddress = PublicMethed.getFinalAddress(witnessKey001);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[1];

    String accountPermissionJson = "";

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey1.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey2.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    ECKey ecKey3 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey3.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    ECKey ecKey4 = new ECKey(Utils.getRandom());

    byte[] newAddress = ecKey4.getAddress();

    String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, threadPoolSize = 20, invocationCount = 20)
    public void testMutiSignForAccount() {
        Integer i = 0;
        while (i < 20) {
            ecKey1 = new ECKey(Utils.getRandom());
            manager1Address = ecKey1.getAddress();
            manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
            ecKey2 = new ECKey(Utils.getRandom());
            manager2Address = ecKey2.getAddress();
            manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());
            ecKey3 = new ECKey(Utils.getRandom());
            ownerAddress = ecKey3.getAddress();
            ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
            PublicMethed.printAddress(ownerKey);
            ecKey4 = new ECKey(Utils.getRandom());
            newAddress = ecKey4.getAddress();
            newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());
            PublicMethed.sendcoin(ownerAddress, 4000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.sendcoin(ownerAddress, 4000000L, fromAddress, testKey002, blockingStubFull);
            PublicMethed.sendcoin(ownerAddress, 4000000L, fromAddress, testKey002, blockingStubFull);
            permissionKeyString[0] = manager1Key;
            permissionKeyString[1] = manager2Key;
            ownerKeyString[0] = ownerKey;
            accountPermissionJson = "[{\"keys\":[{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":2}],\"name\":\"owner\",\"threshold\":2,\"parent\":\"owner\"}," + "{\"parent\":\"owner\",\"keys\":[{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1},{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}],\"name\":\"active\"," + "\"threshold\":2}]";
            // logger.info(accountPermissionJson);
            PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
            String updateName = Long.toString(System.currentTimeMillis());
            PublicMethedForMutiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.freezeBalance(ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.freezeBalance(ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.freezeBalance(ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString);
            PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString);
        }
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestMutiSign003.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestMutiSign003 {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private final String witnessKey001 = Configuration.getByPath("testng.conf").getString("witness.key1");

    private final byte[] witnessAddress = PublicMethed.getFinalAddress(witnessKey001);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[3];

    String accountPermissionJson = "";

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey1.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey2.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    ECKey ecKey3 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey3.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    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");

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true)
    public void testMutiSignForAccount() {
        ecKey1 = new ECKey(Utils.getRandom());
        manager1Address = ecKey1.getAddress();
        manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
        ecKey2 = new ECKey(Utils.getRandom());
        manager2Address = ecKey2.getAddress();
        manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());
        ecKey3 = new ECKey(Utils.getRandom());
        ownerAddress = ecKey3.getAddress();
        ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
        PublicMethed.printAddress(ownerKey);
        ecKey4 = new ECKey(Utils.getRandom());
        newAddress = ecKey4.getAddress();
        newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 9;
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 100000000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        ownerKeyString[2] = manager2Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        String txid = PublicMethedForMutiSign.accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
        final String updateName = Long.toString(System.currentTimeMillis());
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertNotNull(txid);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        long balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        long entropyFee = infoById.get().getReceipt().getEntropyFee();
        long photonFee = infoById.get().getReceipt().getPhotonFee();
        long fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + updateAccountPermissionFee);
        balanceBefore = balanceAfter;
        replacedert.replacedertTrue(PublicMethedForMutiSign.createAccount(ownerAddress, newAddress, ownerKey, blockingStubFull, ownerKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.sendcoinWithPermissionId(newAddress, 100L, ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceWithPermissionId(ownerAddress, 1000000L, 0, 0, ownerKey, blockingStubFull, ownerKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceGetEntropy(ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, ownerKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.freezeBalanceForReceiver(ownerAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), ownerKey, blockingStubFull, ownerKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, blockingStubFull, ownerKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.unFreezeBalanceWithPermissionId(ownerAddress, ownerKey, 0, newAddress, 2, blockingStubFull, permissionKeyString));
        replacedert.replacedertTrue(PublicMethedForMutiSign.updateAccount(ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, ownerKeyString));
        String voteStr = Base58.encode58Check(witnessAddress);
        HashMap<String, String> smallVoteMap = new HashMap<String, String>();
        smallVoteMap.put(voteStr, "1");
        replacedert.replacedertTrue(PublicMethedForMutiSign.voteWitness(smallVoteMap, ownerAddress, ownerKey, blockingStubFull, ownerKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceAfter: " + balanceAfter);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, multiSignFee * 9 + 1000000 + 100);
        replacedert.replacedertTrue(PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull));
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestMutiSign001.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestMutiSign001 {

    private static final long now = System.currentTimeMillis();

    private static final long totalSupply = now;

    private static String name = "MutiSign001_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[2];

    String accountPermissionJson = "";

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey1.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey2.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    ECKey ecKey3 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey3.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    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");

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true)
    public void testMutiSign1Createreplacedetissue() {
        ecKey1 = new ECKey(Utils.getRandom());
        manager1Address = ecKey1.getAddress();
        manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
        ecKey2 = new ECKey(Utils.getRandom());
        manager2Address = ecKey2.getAddress();
        manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());
        ecKey3 = new ECKey(Utils.getRandom());
        ownerAddress = ecKey3.getAddress();
        ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes());
        PublicMethed.printAddress(ownerKey);
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3;
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 2048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        String txid = PublicMethedForMutiSign.accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        long balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        long entropyFee = infoById.get().getReceipt().getEntropyFee();
        long photonFee = infoById.get().getReceipt().getPhotonFee();
        long fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + updateAccountPermissionFee);
        balanceBefore = balanceAfter;
        Long start = System.currentTimeMillis() + 5000;
        Long end = System.currentTimeMillis() + 1000000000;
        logger.info("try create replacedet issue");
        txid = PublicMethedForMutiSign.createreplacedetIssueForTransactionId(ownerAddress, name, totalSupply, 1, 1, start, end, 1, description, url, 2000L, 2000L, 1L, 1L, ownerKey, blockingStubFull, ownerKeyString);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertNotNull(txid);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        entropyFee = infoById.get().getReceipt().getEntropyFee();
        photonFee = infoById.get().getReceipt().getPhotonFee();
        fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + multiSignFee + 1024_000000L);
        logger.info(" create replacedet end");
    }

    /**
     * constructor.
     */
    @Test(enabled = true)
    public void testMutiSign2Transferreplacedetissue() {
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.printAddress(manager1Key);
        Account getreplacedetIdFromOwnerAccount;
        getreplacedetIdFromOwnerAccount = PublicMethed.queryAccount(ownerAddress, blockingStubFull);
        replacedetAccountId1 = getreplacedetIdFromOwnerAccount.getreplacedetIssuedID();
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        String txid = PublicMethedForMutiSign.transferreplacedetForTransactionId(manager1Address, replacedetAccountId1.toByteArray(), 10, ownerAddress, ownerKey, blockingStubFull, ownerKeyString);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertNotNull(txid);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        long balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        long entropyFee = infoById.get().getReceipt().getEntropyFee();
        long photonFee = infoById.get().getReceipt().getPhotonFee();
        long fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + multiSignFee);
    }

    /**
     * constructor.
     */
    @Test(enabled = true)
    public void testMutiSign3Participatereplacedetissue() {
        ecKey4 = new ECKey(Utils.getRandom());
        participateAddress = ecKey4.getAddress();
        participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes());
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 2;
        replacedert.replacedertTrue(PublicMethed.sendcoin(participateAddress, needCoin + 2048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.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\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(participateKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        String txid = PublicMethedForMutiSign.accountPermissionUpdateForTransactionId(accountPermissionJson, participateAddress, participateKey, blockingStubFull, ownerKeyString);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertNotNull(txid);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        long balanceAfter = PublicMethed.queryAccount(participateAddress, blockingStubFull).getBalance();
        long entropyFee = infoById.get().getReceipt().getEntropyFee();
        long photonFee = infoById.get().getReceipt().getPhotonFee();
        long fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + updateAccountPermissionFee);
        balanceBefore = balanceAfter;
        txid = PublicMethedForMutiSign.participatereplacedetIssueForTransactionId(ownerAddress, replacedetAccountId1.toByteArray(), 10, participateAddress, participateKey, 0, blockingStubFull, ownerKeyString);
        replacedert.replacedertNotNull(txid);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        balanceAfter = PublicMethed.queryAccount(participateAddress, blockingStubFull).getBalance();
        entropyFee = infoById.get().getReceipt().getEntropyFee();
        photonFee = infoById.get().getReceipt().getPhotonFee();
        fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee + 10);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + multiSignFee);
    }

    /**
     * constructor.
     */
    @Test(enabled = true)
    public void testMutiSign4updatereplacedetissue() {
        url = "MutiSign001_update_url" + Long.toString(now);
        ownerKeyString[0] = ownerKey;
        description = "MutiSign001_update_description" + Long.toString(now);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        String txid = PublicMethedForMutiSign.updatereplacedetForTransactionId(ownerAddress, description.getBytes(), url.getBytes(), 100L, 100L, ownerKey, 2, blockingStubFull, permissionKeyString);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertNotNull(txid);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        long balanceAfter = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        long entropyFee = infoById.get().getReceipt().getEntropyFee();
        long photonFee = infoById.get().getReceipt().getPhotonFee();
        long fee = infoById.get().getFee();
        logger.info("balanceAfter: " + balanceAfter);
        logger.info("entropyFee: " + entropyFee);
        logger.info("photonFee: " + photonFee);
        logger.info("fee: " + fee);
        replacedert.replacedertEquals(balanceBefore - balanceAfter, fee);
        replacedert.replacedertEquals(fee, entropyFee + photonFee + multiSignFee);
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestZenToken011.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestZenToken011 {

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    Optional<ShieldAddressInfo> sendShieldAddressInfo;

    Optional<ShieldAddressInfo> receiverShieldAddressInfo;

    String sendShieldAddress;

    String receiverShieldAddress;

    List<Note> shieldOutList = new ArrayList<>();

    DecryptNotes notes;

    String memo;

    Note sendNote;

    Note receiverNote;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] zenTokenOwnerAddress = ecKey1.getAddress();

    String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private ManagedChannel channelSolidity = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    private ManagedChannel channelSolidity1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null;

    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 soliditynode1 = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1);

    private String foundationZenTokenKey = Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey");

    byte[] foundationZenTokenAddress = PublicMethed.getFinalAddress(foundationZenTokenKey);

    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 costTokenAmount = 10 * zenTokenFee;

    private Long sendTokenAmount = 8 * zenTokenFee;

    private String txid;

    private Optional<TransactionInfo> infoById;

    private Optional<Transaction> byId;

    /**
     * constructor.
     */
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(foundationZenTokenKey);
        PublicMethed.printAddress(zenTokenOwnerKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
        channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext(true).build();
        blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Args.setFullNodeAllowShieldedTransaction(true);
    }

    @Test(enabled = false, description = "Test get new shield address ")
    public void test1Shield2ShieldTransaction() {
        sendShieldAddress = blockingStubFull.getNewShieldedAddress(GrpcAPI.EmptyMessage.newBuilder().build()).getPaymentAddress();
        memo = "Shield memo in" + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        PublicMethed.transferreplacedet(foundationZenTokenAddress, tokenId, PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity1 != null) {
            channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestZenToken010.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestZenToken010 {

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    Optional<ShieldAddressInfo> sendShieldAddressInfo;

    Optional<ShieldAddressInfo> receiverShieldAddressInfo;

    String sendShieldAddress;

    String receiverShieldAddress;

    List<Note> shieldOutList = new ArrayList<>();

    DecryptNotes notes;

    String memo;

    Note sendNote;

    Note receiverNote;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] zenTokenOwnerAddress = ecKey1.getAddress();

    String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private ManagedChannel channelSolidity = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    private ManagedChannel channelSolidity1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null;

    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 soliditynode1 = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1);

    private String foundationZenTokenKey = Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey");

    byte[] foundationZenTokenAddress = PublicMethed.getFinalAddress(foundationZenTokenKey);

    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 costTokenAmount = 10 * zenTokenFee;

    private Long sendTokenAmount = 8 * zenTokenFee;

    private String txid;

    private Optional<TransactionInfo> infoById;

    private Optional<Transaction> byId;

    /**
     * constructor.
     */
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(foundationZenTokenKey);
        PublicMethed.printAddress(zenTokenOwnerKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
        channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext(true).build();
        blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Args.setFullNodeAllowShieldedTransaction(true);
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo);
        memo = "Shield memo in" + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
    }

    @Test(enabled = false, description = "Shield to itself transaction")
    public void test1Shield2ShieldTransaction() {
        shieldOutList.clear();
        memo = "Send shield to itself memo1 in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo);
        memo = "Send shield to itself memo2 in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + (sendNote.getValue() - 2 * zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.getShieldNotesByIvk(sendShieldAddressInfo, blockingStubFull);
        replacedert.replacedertTrue(notes.getNoteTxsCount() == 3);
        replacedert.replacedertTrue(notes.getNoteTxs(1).getNote().getValue() == zenTokenFee);
        replacedert.replacedertTrue(notes.getNoteTxs(2).getNote().getValue() == sendNote.getValue() - 2 * zenTokenFee);
        replacedert.replacedertEquals(notes.getNoteTxs(1).getNote().getPaymentAddress(), notes.getNoteTxs(2).getNote().getPaymentAddress());
        replacedert.replacedertEquals(notes.getNoteTxs(1).getTxid(), notes.getNoteTxs(2).getTxid());
        replacedert.replacedertTrue(PublicMethed.getSpendResult(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull).getResult());
        notes = PublicMethed.getShieldNotesByOvk(sendShieldAddressInfo, blockingStubFull);
        replacedert.replacedertTrue(notes.getNoteTxsCount() == 2);
    }

    @Test(enabled = false, description = "From shield only have one zenToken fee")
    public void test2Shield2ShieldTransaction() {
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo);
        memo = "Shield memo in" + System.currentTimeMillis();
        shieldOutList.clear();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, 2 * zenTokenFee, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        shieldOutList.clear();
        memo = "Send shield to itself memo1 in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "0", memo);
        memo = "Send shield to itself memo2 in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "0", memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.getShieldNotesByIvk(sendShieldAddressInfo, blockingStubFull);
        replacedert.replacedertTrue(notes.getNoteTxsCount() == 3);
        logger.info("index 0:" + notes.getNoteTxs(0).getNote().getValue());
        logger.info("index 1:" + notes.getNoteTxs(1).getNote().getValue());
        logger.info("index 2:" + notes.getNoteTxs(2).getNote().getValue());
        replacedert.replacedertTrue(notes.getNoteTxs(1).getNote().getValue() == 0);
        replacedert.replacedertTrue(notes.getNoteTxs(2).getNote().getValue() == 0);
        replacedert.replacedertEquals(notes.getNoteTxs(1).getNote().getPaymentAddress(), notes.getNoteTxs(2).getNote().getPaymentAddress());
        replacedert.replacedertEquals(notes.getNoteTxs(1).getTxid(), notes.getNoteTxs(2).getTxid());
    }

    @Test(enabled = false, description = "From public and to public is same one")
    public void test3Public2ShieldAndPublicItselfTransaction() {
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        ecKey1 = new ECKey(Utils.getRandom());
        zenTokenOwnerAddress = ecKey1.getAddress();
        zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        final Long beforereplacedetBalance = PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), blockingStubFull);
        final Long beforeBalance = PublicMethed.queryAccount(zenTokenOwnerAddress, blockingStubFull).getBalance();
        shieldOutList.clear();
        memo = "From public and to public is same one memo in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + 2 * zenTokenFee, memo);
        replacedert.replacedertFalse(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, costTokenAmount, null, null, shieldOutList, zenTokenOwnerAddress, 7 * zenTokenFee, zenTokenOwnerKey, blockingStubFull));
        Long afterreplacedetBalance = PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), blockingStubFull);
        Long afterBalance = PublicMethed.queryAccount(zenTokenOwnerAddress, blockingStubFull).getBalance();
        replacedert.replacedertEquals(beforereplacedetBalance, afterreplacedetBalance);
        replacedert.replacedertEquals(beforeBalance, afterBalance);
        notes = PublicMethed.getShieldNotesByIvk(sendShieldAddressInfo, blockingStubFull);
        replacedert.replacedertTrue(notes.getNoteTxsCount() == 0);
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        PublicMethed.transferreplacedet(foundationZenTokenAddress, tokenId, PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity1 != null) {
            channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestZenToken008.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestZenToken008 {

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    Optional<ShieldAddressInfo> sendShieldAddressInfo;

    Optional<ShieldAddressInfo> receiverShieldAddressInfo;

    String sendShieldAddress;

    String receiverShieldAddress;

    List<Note> shieldOutList = new ArrayList<>();

    DecryptNotes notes;

    String memo;

    Note sendNote;

    Note receiverNote;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] zenTokenOwnerAddress = ecKey1.getAddress();

    String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private ManagedChannel channelSolidity = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    private ManagedChannel channelSolidity1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null;

    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 soliditynode1 = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1);

    private String foundationZenTokenKey = Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey");

    byte[] foundationZenTokenAddress = PublicMethed.getFinalAddress(foundationZenTokenKey);

    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 costTokenAmount = 1 * zenTokenFee + 1;

    private Long sendTokenAmount = 1 * zenTokenFee;

    /**
     * constructor.
     */
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(foundationZenTokenKey);
        PublicMethed.printAddress(zenTokenOwnerKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
        channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext(true).build();
        blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Args.setFullNodeAllowShieldedTransaction(true);
    }

    @Test(enabled = false, description = "Public send 1 token to shield transaction")
    public void test1Shield2ShieldTransaction() {
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo);
        memo = "Shield 1 token memo in " + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "1", memo);
        replacedert.replacedertFalse(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, costTokenAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        replacedert.replacedertTrue(sendNote.getValue() == 1);
    }

    @Test(enabled = false, description = "Shield send 0 token to shield transaction")
    public void test2Shield2ShieldTransaction() {
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, zenTokenFee * 2, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long afterreplacedetBalance = PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull);
        logger.info("token balance is " + afterreplacedetBalance);
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo);
        memo = "Shield costFee token memo in " + System.currentTimeMillis();
        shieldOutList.clear();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo);
        // logger.info();
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, zenTokenFee * 2, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        receiverShieldAddressInfo = PublicMethed.generateShieldAddress();
        receiverShieldAddress = receiverShieldAddressInfo.get().getAddress();
        shieldOutList.clear();
        memo = "Send shield to receiver shield memo in" + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, receiverShieldAddress, "0", memo);
        // Wrong proof
        replacedert.replacedertFalse(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        // Amount is -1
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        shieldOutList.clear();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, receiverShieldAddress, "-1", memo);
        replacedert.replacedertFalse(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        shieldOutList.clear();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, receiverShieldAddress, "0", memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(receiverShieldAddressInfo, blockingStubFull);
        receiverNote = notes.getNoteTxs(0).getNote();
        logger.info("Receiver note:" + receiverNote.toString());
        replacedert.replacedertTrue(receiverNote.getValue() == 0);
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        PublicMethed.transferreplacedet(foundationZenTokenAddress, tokenId, PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity1 != null) {
            channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : WalletTestZenToken002.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced WalletTestZenToken002 {

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    Optional<ShieldAddressInfo> sendShieldAddressInfo;

    Optional<ShieldAddressInfo> receiverShieldAddressInfo;

    String sendShieldAddress;

    String receiverShieldAddress;

    List<Note> shieldOutList = new ArrayList<>();

    DecryptNotes notes;

    String memo;

    Note sendNote;

    Note receiverNote;

    IncrementalMerkleVoucherInfo firstMerkleVoucherInfo;

    IncrementalMerkleVoucherInfo secondMerkleVoucherInfo;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] zenTokenOwnerAddress = ecKey1.getAddress();

    String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private ManagedChannel channelSolidity = null;

    private ManagedChannel channelSolidity1 = null;

    private ManagedChannel channelPbft = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null;

    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 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 = PublicMethed.getFinalAddress(foundationZenTokenKey);

    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 costTokenAmount = 10 * zenTokenFee;

    private Long sendTokenAmount = 8 * zenTokenFee;

    /**
     * constructor.
     */
    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(foundationZenTokenKey);
        PublicMethed.printAddress(zenTokenOwnerKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
        channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext(true).build();
        blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1);
        channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext(true).build();
        blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(zenTokenOwnerAddress, tokenId, costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Args.setFullNodeAllowShieldedTransaction(true);
        sendShieldAddressInfo = PublicMethed.generateShieldAddress();
        sendShieldAddress = sendShieldAddressInfo.get().getAddress();
        logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo);
        memo = "Shield memo in" + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
    }

    @Test(enabled = false, description = "Get merkle tree voucher info")
    public void test01GetMerkleTreeVoucherInfo() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        OutputPointInfo.Builder request = OutputPointInfo.newBuilder();
        // 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());
    }

    @Test(enabled = false, description = "Shield to shield transaction")
    public void test02Shield2ShieldTransaction() {
        receiverShieldAddressInfo = PublicMethed.generateShieldAddress();
        receiverShieldAddress = receiverShieldAddressInfo.get().getAddress();
        shieldOutList.clear();
        ;
        memo = "Send shield to receiver shield memo in" + System.currentTimeMillis();
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, receiverShieldAddress, "" + (sendNote.getValue() - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(null, 0, sendShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        notes = PublicMethed.listShieldNote(receiverShieldAddressInfo, blockingStubFull);
        receiverNote = notes.getNoteTxs(0).getNote();
        logger.info("Receiver note:" + receiverNote.toString());
        replacedert.replacedertTrue(receiverNote.getValue() == sendNote.getValue() - zenTokenFee);
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on FullNode")
    public void test03ScanNoteByIvkAndOvk() {
        // Scan sender note by ovk equals scan receiver note by ivk on FullNode
        Note scanNoteByIvk = PublicMethed.getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote();
        Note scanNoteByOvk = PublicMethed.getShieldNotesByOvk(sendShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue());
        replacedert.replacedertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo());
        replacedert.replacedertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm());
        replacedert.replacedertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on solidity")
    public void test04ScanNoteByIvkAndOvkOnSolidityServer() {
        // Scan sender note by ovk equals scan receiver note by ivk in Solidity
        PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity);
        Note scanNoteByIvk = PublicMethed.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getNote();
        Note scanNoteByOvk = PublicMethed.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue());
        replacedert.replacedertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo());
        replacedert.replacedertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm());
        replacedert.replacedertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on Pbft")
    public void test05ScanNoteByIvkAndOvkOnPbftServer() {
        // Scan sender note by ovk equals scan receiver note by ivk in Solidity
        PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity);
        Note scanNoteByIvk = PublicMethed.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubPbft).getNoteTxs(0).getNote();
        Note scanNoteByOvk = PublicMethed.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubPbft).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue());
        replacedert.replacedertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo());
        replacedert.replacedertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm());
        replacedert.replacedertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on solidity")
    public void test06ScanNoteByIvkAndOvkOnSolidityServer() {
        // Scan sender note by ovk equals scan receiver note by ivk in Solidity
        PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity1);
        Note scanNoteByIvk = PublicMethed.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity1).getNoteTxs(0).getNote();
        Note scanNoteByOvk = PublicMethed.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity1).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue());
        replacedert.replacedertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo());
        replacedert.replacedertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm());
        replacedert.replacedertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Query whether note is spend on solidity")
    public void test07QueryNoteIsSpendOnSolidity() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        // Scan sender note by ovk equals scan receiver note by ivk in Solidity
        replacedert.replacedertTrue(PublicMethed.getSpendResult(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull).getResult());
        replacedert.replacedertTrue(PublicMethed.getSpendResultOnSolidity(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubSolidity).getResult());
        replacedert.replacedertTrue(PublicMethed.getSpendResultOnSolidity(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubSolidity1).getResult());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Query whether note is spend on PBFT")
    public void test08QueryNoteIsSpendOnPbft() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        // Scan sender note by ovk equals scan receiver note by ivk in Solidity
        replacedert.replacedertTrue(PublicMethed.getSpendResult(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull).getResult());
        replacedert.replacedertTrue(PublicMethed.getSpendResultOnSolidity(sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubPbft).getResult());
    }

    /**
     * constructor.
     */
    @Test(enabled = false, description = "Query note and spend status on fullnode and solidity")
    public void test09QueryNoteAndSpendStatusOnFullnode() {
        replacedert.replacedertFalse(PublicMethed.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getIsSpend());
        Note scanNoteByIvk = PublicMethed.getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk, PublicMethed.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote());
        replacedert.replacedertFalse(PublicMethed.getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getIsSpend());
        scanNoteByIvk = PublicMethed.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getNote();
        replacedert.replacedertEquals(scanNoteByIvk, PublicMethed.getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getNote());
        replacedert.replacedertEquals(scanNoteByIvk, PublicMethed.getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubPbft).getNoteTxs(0).getNote());
        shieldOutList.clear();
        memo = "Query note and spend status on fullnode " + System.currentTimeMillis();
        notes = PublicMethed.listShieldNote(receiverShieldAddressInfo, blockingStubFull);
        shieldOutList = PublicMethed.addShieldOutputList(shieldOutList, sendShieldAddress, "" + (notes.getNoteTxs(0).getNote().getValue() - zenTokenFee), memo);
        replacedert.replacedertTrue(PublicMethed.sendShieldCoin(null, 0, receiverShieldAddressInfo.get(), notes.getNoteTxs(0), shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity);
        replacedert.replacedertTrue(PublicMethed.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getIsSpend());
        replacedert.replacedertTrue(PublicMethed.getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity).getNoteTxs(0).getIsSpend());
    }

    @Test(enabled = false, description = "Get merkle tree voucher info")
    public void test10GetMerkleTreeVoucherInfo() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        OutputPointInfo.Builder request = OutputPointInfo.newBuilder();
        // 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());
        replacedert.replacedertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo);
    }

    @Test(enabled = false, description = "Get merkle tree voucher info from Solidity")
    public void test11GetMerkleTreeVoucherInfoFromSolidity() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        OutputPointInfo.Builder request = OutputPointInfo.newBuilder();
        // 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());
        replacedert.replacedertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo);
    }

    @Test(enabled = false, description = "Get merkle tree voucher info from Pbft")
    public void test12GetMerkleTreeVoucherInfoFromPbft() {
        notes = PublicMethed.listShieldNote(sendShieldAddressInfo, blockingStubFull);
        sendNote = notes.getNoteTxs(0).getNote();
        OutputPointInfo.Builder request = OutputPointInfo.newBuilder();
        // 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());
        replacedert.replacedertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo);
    }

    /**
     * constructor.
     */
    @AfterClreplaced(enabled = true)
    public void shutdown() throws InterruptedException {
        PublicMethed.transferreplacedet(foundationZenTokenAddress, tokenId, PublicMethed.getreplacedetIssueValue(zenTokenOwnerAddress, PublicMethed.queryAccount(foundationZenTokenKey, blockingStubFull).getreplacedetIssuedID(), blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity1 != null) {
            channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelPbft != null) {
            channelPbft.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : pedersenHash002.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced pedersenHash002 {

    public final String foundationAccountKey = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    public final byte[] foundationAccountAddress = PublicMethed.getFinalAddress(foundationAccountKey);

    public static final String zenVrc20TokenOwnerKey = Configuration.getByPath("testng.conf").getString("defaultParameter.zenVrc20TokenOwnerKey");

    public static final byte[] zenVrc20TokenOwnerAddress = PublicMethed.getFinalAddress(zenVrc20TokenOwnerKey);

    public static final String zenVrc20TokenOwnerAddressString = PublicMethed.getAddressString(zenVrc20TokenOwnerKey);

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] contractExcAddress = ecKey1.getAddress();

    String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    public ManagedChannel channelFull = null;

    public WalletGrpc.WalletBlockingStub blockingStubFull = null;

    public ManagedChannel channelSolidity = null;

    public WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    public static long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    public ByteString contractAddressByteString;

    public static byte[] contractAddressByte;

    public static String contractAddress;

    public static ByteString shieldAddressByteString;

    public static byte[] shieldAddressByte;

    public static String shieldAddress;

    public static String deployShieldVrc20Txid;

    public static String deployShieldTxid;

    private BigInteger publicFromAmount;

    Optional<ShieldedAddressInfo> receiverShieldAddressInfo;

    List<Note> shieldOutList = new ArrayList<>();

    public static String transfer = "transfer(bytes32[10][],bytes32[2][],bytes32[9][],bytes32[2],bytes32[21][])";

    public Wallet wallet = new Wallet();

    static HttpResponse response;

    static HttpPost httppost;

    public static Integer scalingFactorLogarithm = 0;

    public static Long totalSupply = 1000000000000L;

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true, description = "Deploy shield vrc20 depend contract")
    public void deployShieldVrc20DependContract() {
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
        PublicMethed.printAddress(contractExcKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(contractExcAddress, 10000000000000L, foundationAccountAddress, foundationAccountKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String contractName = "shieldVrc20Token";
        String abi = Configuration.getByPath("testng.conf").getString("abi.abi_shieldVrc20Token");
        String code = Configuration.getByPath("testng.conf").getString("code.code_shieldVrc20Token");
        String constructorStr = "constructor(uint256,string,string)";
        String data = totalSupply.toString() + "," + "\"TokenVRC20\"" + "," + "\"zen20\"";
        logger.info("data:" + data);
        deployShieldVrc20Txid = PublicMethed.deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        logger.info(deployShieldVrc20Txid);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(deployShieldVrc20Txid, 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";
        contractName = "TokenVRC20";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        code = retMap.get("byteCode").toString();
        abi = retMap.get("abI").toString();
        data = "\"" + contractAddress + "\"" + "," + scalingFactorLogarithm;
        constructorStr = "constructor(address,uint256)";
        deployShieldTxid = PublicMethed.deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        logger.info(deployShieldTxid);
        infoById = PublicMethed.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 = PublicMethed.triggerContract(contractAddressByte, "approve(address,uint256)", data, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("approve:" + txid);
        replacedert.replacedertTrue(infoById.get().getReceipt().getResultValue() == 1);
        publicFromAmount = getRandomAmount();
    }

    @Test(enabled = true, description = "left and right value is 0")
    public void test01LeftAndRightValueIsZero() throws Exception {
        // Query account before mint balance
        final Long beforeMintAccountBalance = getBalanceOfShieldVrc20(zenVrc20TokenOwnerAddressString, zenVrc20TokenOwnerAddress, zenVrc20TokenOwnerKey, blockingStubFull);
        // Query contract before mint balance
        final Long beforeMintShieldAccountBalance = getBalanceOfShieldVrc20(shieldAddress, zenVrc20TokenOwnerAddress, zenVrc20TokenOwnerKey, blockingStubFull);
        // Generate new shiled account and set note memo
        receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull);
        String memo = "Shield vrc20 from T account to shield account in" + System.currentTimeMillis();
        String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress();
        shieldOutList.clear();
        shieldOutList = addShieldVrc20OutputList(shieldOutList, receiverShieldAddress, "" + publicFromAmount, memo, blockingStubFull);
        // Create shiled vrc20 parameters
        GrpcAPI.ShieldedVRC20Parameters shieldedVrc20Parameters = createShieldedVrc20Parameters("ByValueIsZero", publicFromAmount, null, null, shieldOutList, "", 0L, blockingStubFull, blockingStubSolidity);
    }

    /**
     * constructor.
     */
    public GrpcAPI.ShieldedVRC20Parameters createShieldedVrc20Parameters(String methodSuffix, BigInteger publicFromAmount, GrpcAPI.DecryptNotesVRC20 inputNoteList, List<ShieldedAddressInfo> shieldedAddressInfoList, List<Note> outputNoteList, String publicToAddress, Long pubicToAmount, WalletGrpc.WalletBlockingStub blockingStubFull, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws ZksnarkException {
        GrpcAPI.PrivateShieldedVRC20Parameters.Builder builder = GrpcAPI.PrivateShieldedVRC20Parameters.newBuilder();
        // Mint type should set public from amount to parameter
        if (publicFromAmount.compareTo(BigInteger.ZERO) > 0) {
            builder.setFromAmount(publicFromAmount.toString());
        }
        builder.setShieldedVRC20ContractAddress(ByteString.copyFrom(shieldAddressByte));
        long valueBalance = 0;
        if (inputNoteList != null) {
            logger.info("Enter transfer type code");
            List<String> rootAndPath = new ArrayList<>();
            for (int i = 0; i < inputNoteList.getNoteTxsCount(); i++) {
                long position = inputNoteList.getNoteTxs(i).getPosition();
                rootAndPath.add(getRootAndPath(methodSuffix, position, blockingStubSolidity));
            }
            if (rootAndPath.isEmpty() || rootAndPath.size() != inputNoteList.getNoteTxsCount()) {
                System.out.println("Can't get all merkle tree, please check the notes.");
                return null;
            }
            for (int i = 0; i < rootAndPath.size(); i++) {
                if (rootAndPath.get(i) == null) {
                    System.out.println("Can't get merkle path, please check the note " + i + ".");
                    return null;
                }
            }
            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<GrpcAPI.ExpandedSpendingKeyMessage> 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());
                }
                Note.Builder noteBuild = Note.newBuilder();
                noteBuild.setPaymentAddress(shieldedAddressInfoList.get(0).getAddress());
                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);
                GrpcAPI.SpendNoteVRC20.Builder spendVRC20NoteBuilder = GrpcAPI.SpendNoteVRC20.newBuilder();
                spendVRC20NoteBuilder.setNote(noteBuild.build());
                spendVRC20NoteBuilder.setAlpha(ByteString.copyFrom(blockingStubFull.getRcm(EmptyMessage.newBuilder().build()).getValue().toByteArray()));
                spendVRC20NoteBuilder.setRoot(ByteString.copyFrom(root));
                spendVRC20NoteBuilder.setPath(ByteString.copyFrom(path));
                spendVRC20NoteBuilder.setPos(inputNoteList.getNoteTxs(i).getPosition());
                valueBalance = Math.addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote().getValue());
                builder.addShieldedSpends(spendVRC20NoteBuilder.build());
            }
        } else {
            // @TODO remove randomOvk by sha256.of(privateKey)
            byte[] ovk = getRandomOvk();
            if (ovk != null) {
                builder.setOvk(ByteString.copyFrom(ovk));
            } else {
                System.out.println("Get random ovk from Rpc failure,please check config");
                return null;
            }
        }
        if (outputNoteList != null) {
            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());
            }
        }
        if (!StringUtil.isNullOrEmpty(publicToAddress)) {
            byte[] to = Commons.decodeFromBase58Check(publicToAddress);
            if (to == null) {
                return null;
            }
            builder.setTransparentToAddress(ByteString.copyFrom(to));
            builder.setToAmount(pubicToAmount.toString());
        }
        try {
            return blockingStubFull.createShieldedContractParameters(builder.build());
        } catch (Exception e) {
            Status status = Status.fromThrowable(e);
            System.out.println("createShieldedContractParameters failed,error " + status.getDescription());
        }
        return null;
    }

    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);
        argsStr = "000000000000000000000000000000000000000000000000" + argsStr;
        TransactionExtention transactionExtention = PublicMethed.triggerConstantContractForExtentionOnSolidity(shieldAddressByte, methodStr, argsStr, true, 0, 1000000000L, "0", 0, zenVrc20TokenOwnerAddress, zenVrc20TokenOwnerKey, blockingStubSolidity);
        byte[] result = transactionExtention.getConstantResult(0).toByteArray();
        return ByteArray.toHexString(result);
    }

    /**
     * constructor.
     */
    public static HttpResponse getNewShieldedAddress(String httpNode) {
        try {
            String requestUrl = "http://" + httpNode + "/wallet/getnewshieldedaddress";
            response = HttpMethed.createConnect(requestUrl);
        } catch (Exception e) {
            e.printStackTrace();
            httppost.releaseConnection();
            return null;
        }
        return response;
    }

    /**
     * constructor.
     */
    public Optional<ShieldedAddressInfo> getNewShieldedAddress(WalletGrpc.WalletBlockingStub blockingStubFull) {
        ShieldedAddressInfo addressInfo = new ShieldedAddressInfo();
        try {
            Optional<BytesMessage> sk = Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build()));
            final Optional<GrpcAPI.DiversifierMessage> d = Optional.of(blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()));
            Optional<GrpcAPI.ExpandedSpendingKeyMessage> expandedSpendingKeyMessage = Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get()));
            BytesMessage.Builder askBuilder = BytesMessage.newBuilder();
            askBuilder.setValue(expandedSpendingKeyMessage.get().getAsk());
            Optional<BytesMessage> ak = Optional.of(blockingStubFull.getAkFromAsk(askBuilder.build()));
            BytesMessage.Builder nskBuilder = BytesMessage.newBuilder();
            nskBuilder.setValue(expandedSpendingKeyMessage.get().getNsk());
            Optional<BytesMessage> nk = Optional.of(blockingStubFull.getNkFromNsk(nskBuilder.build()));
            GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder();
            viewBuilder.setAk(ak.get().getValue());
            viewBuilder.setNk(nk.get().getValue());
            Optional<GrpcAPI.IncomingViewingKeyMessage> ivk = Optional.of(blockingStubFull.getIncomingViewingKey(viewBuilder.build()));
            GrpcAPI.IncomingViewingKeyDiversifierMessage.Builder builder = GrpcAPI.IncomingViewingKeyDiversifierMessage.newBuilder();
            builder.setD(d.get());
            builder.setIvk(ivk.get());
            Optional<GrpcAPI.PaymentAddressMessage> 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());
            addressInfo.setOvk(expandedSpendingKeyMessage.get().getOvk().toByteArray());
            addressInfo.setPkD(addressMessage.get().getPkD().toByteArray());
            return Optional.of(addressInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Optional.empty();
    }

    /**
     * constructor.
     */
    public static List<Note> addShieldVrc20OutputList(List<Note> shieldOutList, String shieldToAddress, String toAmountString, String menoString, WalletGrpc.WalletBlockingStub blockingStubFull) {
        String shieldAddress = shieldToAddress;
        String amountString = toAmountString;
        if (menoString.equals("null")) {
            menoString = "";
        }
        long shieldAmount = 0;
        if (!StringUtil.isNullOrEmpty(amountString)) {
            shieldAmount = Long.valueOf(amountString);
        }
        Note.Builder noteBuild = Note.newBuilder();
        noteBuild.setPaymentAddress(shieldAddress);
        // noteBuild.setPaymentAddress(shieldAddress);
        noteBuild.setValue(shieldAmount);
        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 getBalanceOfShieldVrc20(String queryAddress, byte[] ownerAddress, String ownerKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
        String paramStr = "\"" + queryAddress + "\"";
        TransactionExtention transactionExtention = PublicMethed.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);
                break;
            }
        }
        logger.info(hexBalance);
        return Long.parseLong(hexBalance, 16);
    }

    /**
     * constructor.
     */
    public byte[] getRandomOvk() {
        try {
            Optional<BytesMessage> sk = Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build()));
            Optional<GrpcAPI.ExpandedSpendingKeyMessage> expandedSpendingKeyMessage = Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get()));
            return expandedSpendingKeyMessage.get().getOvk().toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * constructor.
     */
    public BigInteger getRandomAmount() {
        Random random = new Random();
        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];
        return ByteUtil.merge(zeroBytes, longBytes);
    }

    /**
     * constructor.
     */
    public static String getRcm(String httpNode) {
        try {
            String requestUrl = "http://" + httpNode + "/wallet/getrcm";
            response = HttpMethed.createConnect(requestUrl);
        } catch (Exception e) {
            e.printStackTrace();
            httppost.releaseConnection();
            return null;
        }
        return HttpMethed.parseResponseContent(response).getString("value");
    }
}

19 Source : TestValidatemultisign003.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced TestValidatemultisign003 {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[2];

    String accountPermissionJson = "";

    ECKey ecKey001 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey001.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey001.getPrivKeyBytes());

    ECKey ecKey002 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey002.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey002.getPrivKeyBytes());

    ECKey ecKey003 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey003.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey003.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    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.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "Deploy validatemultisign contract")
    public void test001DeployContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 100_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Protocol.Account info = PublicMethed.queryAccount(dev001Key, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = accountResource.getEntropyUsed();
        Long beforePhotonUsed = accountResource.getPhotonUsed();
        Long beforeFreePhotonUsed = accountResource.getFreePhotonUsed();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol";
        String contractName = "validatemultisignTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        contractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        PublicMethed.printAddress(ownerKey);
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3;
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 2048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        replacedert.replacedertTrue(PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true, description = "Trigger validatemultisign precompiled contract, " + "with wrong hash bytes")
    public void test002validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinGetTransaction(fromAddress, 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<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        String argsStr = PublicMethed.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 = PublicMethed.triggerContract(contractAddress, methodStr, AbiUtil.parseParameters(methodStr, Arrays.asList(input)), true, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }

    @Test(enabled = true, description = "Trigger validatemultisign precompiled contract, " + "with correct hash bytes")
    public void test003validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinGetTransaction(fromAddress, 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<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        String argsStr = PublicMethed.parametersString(parameters);
        String input = AbiUtil.parseParameters("validatemultisign(address,uint256,bytes32,bytes[])", argsStr);
        String methodStr = "testMultiPrecompileContract(bytes)";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, AbiUtil.parseParameters(methodStr, Arrays.asList(input)), true, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }
}

19 Source : TestValidatemultisign002.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced TestValidatemultisign002 {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[2];

    String accountPermissionJson = "";

    ECKey ecKey001 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey001.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey001.getPrivKeyBytes());

    ECKey ecKey002 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey002.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey002.getPrivKeyBytes());

    ECKey ecKey003 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey003.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey003.getPrivKeyBytes());

    ECKey ecKey004 = new ECKey(Utils.getRandom());

    byte[] manager4Address = ecKey004.getAddress();

    String manager4Key = ByteArray.toHexString(ecKey004.getPrivKeyBytes());

    ECKey ecKey005 = new ECKey(Utils.getRandom());

    byte[] manager5Address = ecKey005.getAddress();

    String manager5Key = ByteArray.toHexString(ecKey005.getPrivKeyBytes());

    ECKey ecKey006 = new ECKey(Utils.getRandom());

    byte[] manager6Address = ecKey006.getAddress();

    String manager6Key = ByteArray.toHexString(ecKey006.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    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());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "Deploy validatemultisign contract")
    public void test001DeployContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 100_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Protocol.Account info = PublicMethed.queryAccount(dev001Key, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = accountResource.getEntropyUsed();
        Long beforePhotonUsed = accountResource.getPhotonUsed();
        Long beforeFreePhotonUsed = accountResource.getFreePhotonUsed();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol";
        String contractName = "validatemultisignTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        contractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        PublicMethed.printAddress(ownerKey);
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3;
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 2048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethed.getAddressString(manager4Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager5Key) + "\",\"weight\":1}," + "]}]}";
        logger.info(accountPermissionJson);
        replacedert.replacedertTrue(PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true, description = "Trigger validatemultisign with signatures num")
    public void test002validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        int permissionId = 2;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 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.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        // Trigger with one signature
        List<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with five signature
        signatures.clear();
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey002.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with six signature
        signatures.clear();
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey002.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey006.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }

    @Test(enabled = true, description = "Trigger validatemultisign with Duplicate signatures")
    public void test003validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        int permissionId = 2;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 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
        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<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // 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(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // 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()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }

    @Test(enabled = true, description = "Trigger validatemultisign with weight")
    public void test004validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        int permissionId = 2;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 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
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray()));
        List<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }
}

19 Source : TestValidatemultisign001.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced TestValidatemultisign001 {

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    ByteString replacedetAccountId1;

    String[] permissionKeyString = new String[2];

    String[] ownerKeyString = new String[2];

    String accountPermissionJson = "";

    ECKey ecKey001 = new ECKey(Utils.getRandom());

    byte[] manager1Address = ecKey001.getAddress();

    String manager1Key = ByteArray.toHexString(ecKey001.getPrivKeyBytes());

    ECKey ecKey002 = new ECKey(Utils.getRandom());

    byte[] manager2Address = ecKey002.getAddress();

    String manager2Key = ByteArray.toHexString(ecKey002.getPrivKeyBytes());

    ECKey ecKey003 = new ECKey(Utils.getRandom());

    byte[] ownerAddress = ecKey003.getAddress();

    String ownerKey = ByteArray.toHexString(ecKey003.getPrivKeyBytes());

    ECKey ecKey004 = new ECKey(Utils.getRandom());

    byte[] participateAddress = ecKey004.getAddress();

    String participateKey = ByteArray.toHexString(ecKey004.getPrivKeyBytes());

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    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());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "Deploy validatemultisign contract")
    public void test001DeployContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 100_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Protocol.Account info = PublicMethed.queryAccount(dev001Key, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = accountResource.getEntropyUsed();
        Long beforePhotonUsed = accountResource.getPhotonUsed();
        Long beforeFreePhotonUsed = accountResource.getFreePhotonUsed();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol";
        String contractName = "validatemultisignTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        contractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        PublicMethed.printAddress(ownerKey);
        long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3;
        replacedert.replacedertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 2048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull).getBalance();
        logger.info("balanceBefore: " + balanceBefore);
        permissionKeyString[0] = manager1Key;
        permissionKeyString[1] = manager2Key;
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + "]}]}";
        logger.info(accountPermissionJson);
        replacedert.replacedertTrue(PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true, description = "Trigger validatemultisign contract with " + "Permission(address) case")
    public void test002validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinGetTransaction(fromAddress, 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<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with wrong Permission address
        merged = ByteUtil.merge(dev001Address, ByteArray.fromInt(0), hash);
        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(StringUtil.encode58Check(dev001Address), 0, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with address that have not permission
        merged = ByteUtil.merge(fromAddress, ByteArray.fromInt(0), hash);
        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(StringUtil.encode58Check(fromAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with not exist address
        merged = ByteUtil.merge(manager1Address, ByteArray.fromInt(0), hash);
        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(StringUtil.encode58Check(manager1Address), 0, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with error format address
        merged = ByteUtil.merge(manager1Address, ByteArray.fromInt(0), hash);
        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);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }

    @Test(enabled = true, description = "Trigger validatemultisign contract with " + "Permission(permissionId) case")
    public void test003validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinGetTransaction(fromAddress, 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);
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        List<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with error format PermissionID
        permissionId = 100;
        merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash);
        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(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // 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);
        signatures.clear();
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // 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);
        signatures.clear();
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), permissionId, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }

    @Test(enabled = true, description = "Trigger validatemultisign contract with " + "Permission(hash) case")
    public void test004validatemultisign() {
        List<Object> signatures = new ArrayList<>();
        ownerKeyString[0] = ownerKey;
        ownerKeyString[1] = manager1Key;
        Transaction transaction = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 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);
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        // Trigger with no sign hash
        List<Object> parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        String input = PublicMethed.parametersString(parameters);
        String methodStr = "testmulti(address,uint256,bytes32,bytes[])";
        String TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // Trigger with wrong hash
        transaction = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 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);
        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(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
        // 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 = PublicMethedForMutiSign.sendcoinWithPermissionIdNotSign(fromAddress, 1L, dev001Address, 0, dev001Key, blockingStubFull);
        transaction = TransactionUtils.setTimestamp(transaction);
        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);
        signatures.clear();
        signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray()));
        signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray()));
        parameters = Arrays.asList(StringUtil.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures);
        input = PublicMethed.parametersString(parameters);
        TriggerTxid = PublicMethed.triggerContract(contractAddress, methodStr, input, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(TriggerTxid, blockingStubFull);
        logger.info("infoById" + infoById);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()));
    }
}

19 Source : TransferFailed003.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced TransferFailed003 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 10000000L;

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testNetAccountKey = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    byte[] contractAddress = 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 ManagedChannel channelSolidity = null;

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private ManagedChannel channelFull1 = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    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);

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(contractExcKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext(true).build();
        blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
    }

    @Test(enabled = true, description = "TransferToken enough tokenBalance")
    public void test1TransferTokenEnough() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(contractExcAddress, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, contractExcKey, blockingStubFull));
        String filePath = "src/test/resources/soliditycode/TransferFailed001.sol";
        String contractName = "EntropyOfTransferFailedTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        replacedetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull).getreplacedetIssuedID();
        contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, 1000000000L, replacedetAccountId.toStringUtf8(), 100L, null, contractExcKey, contractExcAddress, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // replacedert.replacedertTrue(PublicMethed.transferreplacedet(contractAddress,
        // replacedetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey,
        // blockingStubFull));
        // PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore);
        logger.info("contractAccountCountBefore:" + contractAccountCountBefore);
        String txid = "";
        String num = "1" + ",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenInsufficientBalance(uint256,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertTrue(testNetAccountCountBefore + 1 == testNetAccountCountAfter);
        replacedert.replacedertTrue(contractAccountCountBefore - 1 == contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
    }

    @Test(enabled = true, description = "TransferToken insufficient tokenBalance")
    public void test2TransferTokenNotEnough() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore);
        logger.info("contractAccountCountBefore:" + contractAccountCountBefore);
        String txid = "";
        String num = "1000" + ",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenInsufficientBalance(uint256,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        logger.info("infoById:" + infoById);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray()));
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertNotEquals(10000000, entropyUsageTotal);
    }

    @Test(enabled = true, description = "TransferToken to nonexistent target")
    public void test3TransferTokenNonexistentTarget() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        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) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenNonexistentTarget(uint256,address,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore - 1, contractAccountCountAfter.longValue());
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertNotEquals(10000000, entropyUsageTotal);
        Long nonexistentAddressAccount = PublicMethed.getreplacedetIssueValue(nonexistentAddress, replacedetAccountId, blockingStubFull1);
        replacedert.replacedertEquals(1L, nonexistentAddressAccount.longValue());
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenNonexistentTarget(uint256,address,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        fee = infoById.get().getFee();
        photonUsed = infoById.get().getReceipt().getPhotonUsage();
        entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal2 = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal2);
        infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        afterBalance = infoafter.getBalance();
        afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertEquals(0, infoById.get().getResultValue());
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore - 2, contractAccountCountAfter.longValue());
        replacedert.replacedertEquals(entropyUsageTotal, entropyUsageTotal2 + EntropyCost.getInstance().getNEW_ACCT_CALL());
        nonexistentAddressAccount = PublicMethed.getreplacedetIssueValue(nonexistentAddress, replacedetAccountId, blockingStubFull1);
        replacedert.replacedertEquals(2L, nonexistentAddressAccount.longValue());
    }

    @Test(enabled = true, description = "TransferToken to myself")
    public void test4TransferTokenSelf() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore);
        logger.info("contractAccountCountBefore:" + contractAccountCountBefore);
        String txid = "";
        String num = "1" + ",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenSelf(uint256,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult());
        replacedert.replacedertEquals("transfer vrc10 failed: Cannot transfer replacedet to yourself.", ByteArray.toStr(infoById.get().getResMessage().toByteArray()));
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertNotEquals(10000000, entropyUsageTotal);
    }

    @Test(enabled = true, description = "TransferToken notexist tokenID ")
    public void test5TransferTokenNotexist() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore);
        logger.info("contractAccountCountBefore:" + contractAccountCountBefore);
        String txid = "";
        String fakereplacedetAccountId = Long.toString(0L);
        String num = "1" + ",\"" + fakereplacedetAccountId + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenInsufficientBalance(uint256,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray()));
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
    }

    @Test(enabled = true, description = "TransferToken to nonexistent target and " + "insufficient tokenBalance")
    public void test7TransferTokenNonexistentTarget() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        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) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenNonexistentTarget(uint256,address,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray()));
        replacedert.replacedertEquals(afterBalance + fee, beforeBalance.longValue());
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertNotEquals(10000000, entropyUsageTotal);
    }

    @Test(enabled = true, description = "TransferToken to myself and insufficient tokenBalance")
    public void test8TransferTokenSelf() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore);
        logger.info("contractAccountCountBefore:" + contractAccountCountBefore);
        String txid = "";
        String num = "1000000000000000" + ",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenSelf(uint256,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray()));
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertNotEquals(10000000, entropyUsageTotal);
    }

    @Test(enabled = true, description = "TransferToken to nonexistent target, but revert")
    public void test9TransferTokenNonexistentTargetRevert() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long testNetAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        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) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenRevert(uint256,address,vrcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        logger.info("infoById:" + infoById);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull1);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long testNetAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        Long contractAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter);
        logger.info("contractAccountCountAfter:" + contractAccountCountAfter);
        replacedert.replacedertEquals(1, infoById.get().getResultValue());
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertEquals(testNetAccountCountBefore, testNetAccountCountAfter);
        replacedert.replacedertEquals(contractAccountCountBefore, contractAccountCountAfter);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        replacedert.replacedertTrue(entropyUsageTotal > EntropyCost.getInstance().getNEW_ACCT_CALL());
        Long nonexistentAddressAccount = PublicMethed.getreplacedetIssueValue(nonexistentAddress, replacedetAccountId, blockingStubFull1);
        replacedert.replacedertEquals(0L, nonexistentAddressAccount.longValue());
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelFull1 != null) {
            channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractTestSendCoin001.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractTestSendCoin001 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "Sendcoin and transferreplacedet to contractAddresss ," + "then selfdestruct")
    public void testSendCoinAndTransferreplacedetContract001() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 3100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "src/test/resources/soliditycode/contractVrcToken031.sol";
        String contractName = "token";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 100;
        long callValue = 5;
        final String deployContractTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(deployContractTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (deployContractTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage().toStringUtf8());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        Return ret = PublicMethed.transferreplacedetForReturn(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet to smartContract.", ret.getMessage().toStringUtf8());
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        Return ret1 = PublicMethed.sendcoinForReturn(transferTokenContractAddress, 1_000_000L, fromAddress, testKey002, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer VS to a smartContract.", ret1.getMessage().toStringUtf8());
        String num = "\"" + Base58.encode58Check(dev001Address) + "\"";
        String txid = PublicMethed.triggerContract(transferTokenContractAddress, "kill(address)", num, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        long contractBefore = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(transferTokenContractAddress, 1_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        long contractAfetr = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        replacedert.replacedertTrue(contractreplacedetCountBefore + 100L == contractreplacedetCountAfter);
        replacedert.replacedertTrue(contractBefore + 1_000_000L == contractAfetr);
    }

    @Test(enabled = true, description = "Use create to generate a contract address " + "Sendcoin and transferreplacedet to contractAddresss ,then selfdestruct,")
    public void testSendCoinAndTransferreplacedetContract002() {
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "src/test/resources/soliditycode/contractTransferToken001.sol";
        String contractName = "A";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 100;
        long callValue = 5;
        final String deployContractTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(deployContractTxid, blockingStubFull);
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        String txid = PublicMethed.triggerContract(transferTokenContractAddress, "newB()", "#", false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.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);
        logger.info("a:" + ByteArray.toHexString(a));
        logger.info("b:" + ByteArray.toHexString(b));
        logger.info("c:" + ByteArray.toHexString(c));
        logger.info("d:" + ByteArray.toHexString(d));
        logger.info("41" + ByteArray.toHexString(d));
        String exceptedResult = "41" + ByteArray.toHexString(d);
        String realResult = ByteArray.toHexString(b);
        replacedert.replacedertEquals(realResult, "00");
        replacedert.replacedertNotEquals(realResult, "41");
        String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult));
        logger.info("create Address : " + addressFinal);
        byte[] testContractAddress = WalletClient.decodeFromBase58Check(addressFinal);
        Return ret = PublicMethed.transferreplacedetForReturn(testContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet to smartContract.", ret.getMessage().toStringUtf8());
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(testContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(0L), contractreplacedetCount);
        Return ret1 = PublicMethed.sendcoinForReturn(testContractAddress, 1_000_000L, fromAddress, testKey002, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer VS to a smartContract.", ret1.getMessage().toStringUtf8());
        String num = "\"" + Base58.encode58Check(dev001Address) + "\"";
        txid = PublicMethed.triggerContract(testContractAddress, "kill(address)", num, false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(testContractAddress, replacedetAccountId, blockingStubFull);
        long contractBefore = PublicMethed.queryAccount(testContractAddress, blockingStubFull).getBalance();
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(testContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(testContractAddress, 1_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(testContractAddress, replacedetAccountId, blockingStubFull);
        long contractAfetr = PublicMethed.queryAccount(testContractAddress, blockingStubFull).getBalance();
        replacedert.replacedertTrue(contractreplacedetCountBefore + 100L == contractreplacedetCountAfter);
        replacedert.replacedertTrue(contractBefore + 1_000_000L == contractAfetr);
    }

    @Test(enabled = true, description = "Use create2 to generate a contract address \"\n" + "      + \"Sendcoin and transferreplacedet to contractAddresss ,then selfdestruct")
    public void testSendCoinAndTransferreplacedetContract003() {
        ECKey ecKey1 = new ECKey(Utils.getRandom());
        byte[] contractExcAddress = ecKey1.getAddress();
        String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
        String sendcoin = PublicMethed.sendcoinGetTransactionId(contractExcAddress, 1000000000L, fromAddress, testKey002, blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(contractExcAddress, 1000000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById0 = null;
        infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull);
        logger.info("infoById0   " + infoById0.get());
        replacedert.replacedertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), "");
        replacedert.replacedertEquals(infoById0.get().getResult().getNumber(), 0);
        Optional<Transaction> ById = PublicMethed.getTransactionById(sendcoin, blockingStubFull);
        replacedert.replacedertEquals(ById.get().getRet(0).getContractRet().getNumber(), SUCCESS_VALUE);
        replacedert.replacedertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE);
        replacedert.replacedertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS);
        String filePath = "src/test/resources/soliditycode/create2contractn2.sol";
        String contractName = "Factory";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        String contractName1 = "TestConstract";
        HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1);
        String code1 = retMap1.get("byteCode").toString();
        String abi1 = retMap1.get("abI").toString();
        String txid = "";
        String num = "\"" + code1 + "\"" + "," + 1;
        txid = PublicMethed.triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterBalance + fee == beforeBalance);
        replacedert.replacedertTrue(beforeEntropyUsed + entropyUsed >= afterEntropyUsed);
        replacedert.replacedertTrue(beforeFreePhotonUsed + photonUsed >= afterFreePhotonUsed);
        replacedert.replacedertTrue(beforePhotonUsed + photonUsed >= afterPhotonUsed);
        byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray();
        String returnAddress = Base58.encode58Check(returnAddressBytes);
        logger.info("returnAddress:" + returnAddress);
        Return ret = PublicMethed.transferreplacedetForReturn(returnAddressBytes, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet to smartContract.", ret.getMessage().toStringUtf8());
        Return ret1 = PublicMethed.transferreplacedetForReturn(returnAddressBytes, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet to smartContract.", ret1.getMessage().toStringUtf8());
        txid = PublicMethed.triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById1 = null;
        infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee1 = infoById1.get().getFee();
        Long photonUsed1 = infoById1.get().getReceipt().getPhotonUsage();
        Long entropyUsed1 = infoById1.get().getReceipt().getEntropyUsage();
        Long photonFee1 = infoById1.get().getReceipt().getPhotonFee();
        long entropyUsageTotal1 = infoById1.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee1:" + fee1);
        logger.info("photonUsed1:" + photonUsed1);
        logger.info("entropyUsed1:" + entropyUsed1);
        logger.info("photonFee1:" + photonFee1);
        logger.info("entropyUsageTotal1:" + entropyUsageTotal1);
        Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        Long afterBalance1 = infoafter1.getBalance();
        Long afterEntropyUsed1 = resourceInfoafter1.getEntropyUsed();
        Long afterPhotonUsed1 = resourceInfoafter1.getPhotonUsed();
        Long afterFreePhotonUsed1 = resourceInfoafter1.getFreePhotonUsed();
        logger.info("afterBalance:" + afterBalance1);
        logger.info("afterEntropyUsed:" + afterEntropyUsed1);
        logger.info("afterPhotonUsed:" + afterPhotonUsed1);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed1);
        replacedert.replacedertTrue(infoById1.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterBalance1 + fee1 == afterBalance);
        replacedert.replacedertTrue(afterEntropyUsed + entropyUsed1 >= afterEntropyUsed1);
        Long returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray())));
        replacedert.replacedertTrue(1 == returnnumber);
        txid = PublicMethed.triggerContract(returnAddressBytes, "set()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        txid = PublicMethed.triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray())));
        replacedert.replacedertTrue(5 == returnnumber);
        String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\"";
        txid = PublicMethed.triggerContract(returnAddressBytes, "testSuicideNonexistentTarget(address)", param1, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        replacedert.replacedertEquals("suicide", ByteArray.toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray()));
        TransactionExtention transactionExtention = PublicMethed.triggerContractForExtention(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR"));
        replacedert.replacedertThat(transactionExtention.getResult().getMessage().toStringUtf8(), containsString("contract validate error : No contract or not a valid smart contract"));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(returnAddressBytes, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(returnAddressBytes, 1_000_000L, fromAddress, testKey002, blockingStubFull));
        txid = PublicMethed.triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById3 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        byte[] returnAddressBytes1 = infoById3.get().getInternalTransactions(0).getTransferToAddress().toByteArray();
        String returnAddress1 = Base58.encode58Check(returnAddressBytes1);
        replacedert.replacedertEquals(returnAddress1, returnAddress);
        txid = PublicMethed.triggerContract(returnAddressBytes1, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray())));
        replacedert.replacedertTrue(1 == returnnumber);
        ret = PublicMethed.transferreplacedetForReturn(returnAddressBytes1, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet to smartContract.", ret.getMessage().toStringUtf8());
        ret1 = PublicMethed.transferreplacedetForReturn(returnAddressBytes1, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode());
        replacedert.replacedertEquals("contract validate error : Cannot transfer replacedet 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.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : Create2Test021.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced Create2Test021 {

    private static final long now = System.currentTimeMillis();

    private static final String name = "replacedet008_" + Long.toString(now);

    private static final long totalSupply = now;

    private final String testNetAccountKey = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);

    byte[] contractAddress = null;

    ECKey ecKey1 = new ECKey(Utils.getRandom());

    byte[] bytes;

    String description = "just-test";

    String url = "https://github.com/tronprotocol/wallet-cli/";

    ByteString replacedetAccountId = null;

    ECKey ecKey2 = new ECKey(Utils.getRandom());

    byte[] resourceOnwerAddress = ecKey2.getAddress();

    String resourceOnwerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private ManagedChannel channelSolidity = null;

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private ManagedChannel channelFull1 = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull1 = null;

    private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

    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 byte[] contractExcAddress = PublicMethed.getFinalAddress("9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4");

    private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4";

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        PublicMethed.printAddress(contractExcKey);
        PublicMethed.printAddress(resourceOnwerKey);
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext(true).build();
        blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1);
        channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext(true).build();
        blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
    }

    @Test(enabled = true, description = "TriggerContract a constant function created by create2")
    public void test1TriggerContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(resourceOnwerAddress, 1000000000L + 1024000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // Create 3 the same name token.
        Long start = System.currentTimeMillis() + 2000;
        Long end = System.currentTimeMillis() + 1000000000;
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(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 = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        bytes = ByteArray.fromHexString("416CED4D6BF0AE10676347961BEFB7F47A8664AE36");
        String param2 = "\"" + Base58.encode58Check(contractExcAddress) + "\"";
        String txidn = PublicMethed.triggerContract(bytes, "testSuicideNonexistentTarget(address)", param2, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull));
        // Trigger contract to transfer trx and token.
        Account getreplacedetIdFromAccount = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull);
        replacedetAccountId = getreplacedetIdFromAccount.getreplacedetIssuedID();
        Long contractBeforeBalance = PublicMethed.queryAccount(bytes, blockingStubFull).getBalance();
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(bytes, replacedetAccountId.toByteArray(), 100, resourceOnwerAddress, resourceOnwerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account account1 = PublicMethed.queryAccount(bytes, blockingStubFull);
        int typeValue1 = account1.getTypeValue();
        replacedert.replacedertEquals(0, typeValue1);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 0, ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 1, ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        final Long beforeExcAccountBalance = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance();
        replacedert.replacedertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getPhotonLimit() > 0);
        replacedert.replacedertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEntropyLimit() > 0);
        String contractName1 = "TestConstract";
        HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1);
        String code1 = "6080604052600160005534801561001557600080fd5b50d3801561002257600080fd5b50" + "d2801561002f57600080fd5b506101fd8061003f6000396000f3fe60806040526004361061005b577" + "c01000000000000000000000000000000000000000000000000000000006000350463040821fc8114" + "61006057806317b6ad5b1461007f578063cc133e94146100b2578063e5aa3d58146100d5575b60008" + "0fd5b61007d6004803603602081101561007657600080fd5b5035610116565b005b61007d60048036" + "03602081101561009557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610" + "147565b61007d600480360360408110156100c857600080fd5b5080359060200135610160565b3480" + "156100e157600080fd5b50d380156100ee57600080fd5b50d280156100fb57600080fd5b506101046" + "101cb565b60408051918252519081900360200190f35b604051339082156108fc0290839060008181" + "81858888f19350505050158015610143573d6000803e3d6000fd5b5050565b8073fffffffffffffff" + "fffffffffffffffffffffffff16ff5b3382156108fc0283838015801561017657600080fd5b508067" + "80000000000000001115801561018e57600080fd5b5080620f4240101580156101a157600080fd5b5" + "0604051600081818185878a8ad09450505050501580156101c6573d6000803e3d6000fd5b50505056" + "5b6000548156fea165627a7a72305820485b773c60fed3b76621350dd3da7ecf152a2d37ca02dc195" + "d6f8a26aec196850029";
        String abi1 = retMap1.get("abI").toString();
        String txid = "";
        String num = "\"" + code1 + "\"" + "," + 1;
        txid = PublicMethed.triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertFalse(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 0, ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull));
        replacedert.replacedertFalse(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 1, ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull));
        Long afterExcAccountBalance = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance();
        replacedert.replacedertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getPhotonLimit() == 0);
        replacedert.replacedertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEntropyLimit() == 0);
        logger.info("afterExcAccountBalance: " + afterExcAccountBalance);
        logger.info("beforeExcAccountBalance:" + beforeExcAccountBalance);
        replacedert.replacedertTrue(afterExcAccountBalance - beforeExcAccountBalance == 0);
        replacedert.replacedertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, 0, bytes, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, 1, bytes, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long afterUnfreezeBalance = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance();
        replacedert.replacedertTrue(afterUnfreezeBalance == beforeExcAccountBalance + 1000000L * 2);
        Optional<TransactionInfo> infoById = null;
        infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee = infoById.get().getFee();
        Long photonUsed = infoById.get().getReceipt().getPhotonUsage();
        Long entropyUsed = infoById.get().getReceipt().getEntropyUsage();
        Long photonFee = infoById.get().getReceipt().getPhotonFee();
        long entropyUsageTotal = infoById.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee:" + fee);
        logger.info("photonUsed:" + photonUsed);
        logger.info("entropyUsed:" + entropyUsed);
        logger.info("photonFee:" + photonFee);
        logger.info("entropyUsageTotal:" + entropyUsageTotal);
        Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray();
        String returnAddress = Base58.encode58Check(returnAddressBytes);
        replacedert.replacedertEquals(Base58.encode58Check(bytes), returnAddress);
        logger.info("returnAddress:" + returnAddress);
        txid = PublicMethed.triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById1 = null;
        infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        Long fee1 = infoById1.get().getFee();
        Long photonUsed1 = infoById1.get().getReceipt().getPhotonUsage();
        Long entropyUsed1 = infoById1.get().getReceipt().getEntropyUsage();
        Long photonFee1 = infoById1.get().getReceipt().getPhotonFee();
        long entropyUsageTotal1 = infoById1.get().getReceipt().getEntropyUsageTotal();
        logger.info("fee1:" + fee1);
        logger.info("photonUsed1:" + photonUsed1);
        logger.info("entropyUsed1:" + entropyUsed1);
        logger.info("photonFee1:" + photonFee1);
        logger.info("entropyUsageTotal1:" + entropyUsageTotal1);
        Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
        AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull);
        Long afterBalance1 = infoafter1.getBalance();
        Long afterEntropyUsed1 = resourceInfoafter1.getEntropyUsed();
        Long afterPhotonUsed1 = resourceInfoafter1.getPhotonUsed();
        Long afterFreePhotonUsed1 = resourceInfoafter1.getFreePhotonUsed();
        logger.info("afterBalance:" + afterBalance1);
        logger.info("afterEntropyUsed:" + afterEntropyUsed1);
        logger.info("afterPhotonUsed:" + afterPhotonUsed1);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed1);
        replacedert.replacedertTrue(infoById1.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterBalance1 + fee1 == afterBalance);
        replacedert.replacedertTrue(afterEntropyUsed + entropyUsed1 >= afterEntropyUsed1);
        Long returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray())));
        replacedert.replacedertTrue(1 == returnnumber);
        Account account = PublicMethed.queryAccount(returnAddressBytes, blockingStubFull);
        int typeValue = account.getTypeValue();
        replacedert.replacedertEquals(2, typeValue);
        replacedert.replacedertEquals(account.getBalance(), 1000000);
    }

    @Test(enabled = true, description = "Create2 contract can transfer vs and token.")
    public void test2TriggerContract() {
        Account accountbefore = PublicMethed.queryAccount(bytes, blockingStubFull);
        int typeValue = accountbefore.getTypeValue();
        replacedert.replacedertEquals(2, typeValue);
        long accountbeforeBalance = accountbefore.getBalance();
        replacedert.replacedertEquals(accountbeforeBalance, 1000000);
        Account contractExcAddressbefore = PublicMethed.queryAccount(contractExcAddress, blockingStubFull);
        long contractExcAddressbeforeBalance = contractExcAddressbefore.getBalance();
        String num = "1";
        String txid = PublicMethed.triggerContract(bytes, "testTransfer(uint256)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> transactionInfoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        replacedert.replacedertTrue(transactionInfoById.get().getResultValue() == 0);
        Long fee1 = transactionInfoById.get().getFee();
        Account accountafter = PublicMethed.queryAccount(bytes, blockingStubFull);
        long accountafterBalance = accountafter.getBalance();
        replacedert.replacedertTrue(accountbeforeBalance - 1 == accountafterBalance);
        Account contractExcAddressafter = PublicMethed.queryAccount(contractExcAddress, blockingStubFull);
        long contractExcAddressafterBalance = contractExcAddressafter.getBalance();
        replacedert.replacedertTrue(contractExcAddressbeforeBalance + 1 - fee1 == contractExcAddressafterBalance);
        num = "1" + ",\"" + replacedetAccountId.toStringUtf8() + "\"";
        Long returnAddressBytesAccountCountBefore = PublicMethed.getreplacedetIssueValue(bytes, replacedetAccountId, blockingStubFull);
        Long contractExcAddressAccountCountBefore = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        String txid1 = PublicMethed.triggerContract(bytes, "testTransferToken(uint256,vrcToken)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> transactionInfoById1 = PublicMethed.getTransactionInfoById(txid1, blockingStubFull);
        replacedert.replacedertTrue(transactionInfoById1.get().getResultValue() == 0);
        Long returnAddressBytesAccountCountAfter = PublicMethed.getreplacedetIssueValue(bytes, replacedetAccountId, blockingStubFull);
        Long contractExcAddressAccountCountAfter = PublicMethed.getreplacedetIssueValue(contractExcAddress, replacedetAccountId, blockingStubFull);
        replacedert.replacedertTrue(returnAddressBytesAccountCountBefore - 1 == returnAddressBytesAccountCountAfter);
        replacedert.replacedertTrue(contractExcAddressAccountCountBefore + 1 == contractExcAddressAccountCountAfter);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelFull1 != null) {
            channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
        if (channelSolidity != null) {
            channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken080.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken080 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "DeployContract with 0 tokenValue and tokenId")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken080.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 100;
        long callValue = 10;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        // get and verify the msg.value and msg.id
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getResultInCon()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        if (infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("The msg value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken079.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken079 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "Trigger transferToken with 0 tokenValue and tokenId")
    public void triggerTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken079.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 200;
        long callValue = 0;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(200), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(200), contractreplacedetCount);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        PublicMethed.sendcoin(transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        tokenId = Long.toString(0);
        tokenValue = 0;
        callValue = 5;
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<Transaction> trsById = PublicMethed.getTransactionById(triggerTxid, blockingStubFull);
        long feeLimit = trsById.get().getRawData().getFeeLimit();
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        logger.info("the value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken075.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken075 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "TokenBalance with exception condition")
    public void testTokenBalanceContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 11000_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken075.sol";
        String contractName = "Dest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 200;
        long callValue = 5;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        // get and verify the msg.value and msg.id
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long devreplacedetBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, dev001Address has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + devreplacedetBefore);
        tokenId = Long.toString(100_0000);
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        tokenId = Long.toString(0);
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        tokenId = Long.toString(-1);
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        tokenId = Long.toString(Long.MIN_VALUE);
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenLongMin()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenLongMax()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        // replacedert.replacedertEquals("BigInteger out of long range",
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken073.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken073 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "TokenBalance with correct tokenValue and tokenId")
    public void testTokenBalanceContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 11000_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 300000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken073.sol";
        String contractName = "Dest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 200;
        long callValue = 5;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        // get and verify the msg.value and msg.id
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long devreplacedetBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, dev001Address has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + devreplacedetBefore);
        tokenId = replacedetAccountId.toStringUtf8();
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        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());
        logger.info("msgTokenBalance: " + msgTokenBalance);
        logger.info("msgId: " + msgId);
        logger.info("msgTokenValue: " + msgTokenValue);
        replacedert.replacedertEquals(msgTokenBalance, devreplacedetBefore);
        tokenId = Long.toString(Long.valueOf(replacedetAccountId.toStringUtf8()) + 1000);
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        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());
        logger.info("msgTokenBalance: " + msgTokenBalance);
        logger.info("msgId: " + msgId);
        logger.info("msgTokenValue: " + msgTokenValue);
        replacedert.replacedertEquals(Long.valueOf(0), msgTokenBalance);
        tokenId = Long.toString(Long.MAX_VALUE);
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(vrcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        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());
        logger.info("msgTokenBalance: " + msgTokenBalance);
        logger.info("msgId: " + msgId);
        logger.info("msgTokenValue: " + msgTokenValue);
        replacedert.replacedertEquals(Long.valueOf(0), msgTokenBalance);
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken067.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken067 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private byte[] resultContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, " + "and not existed tokenId, deploy transfer contract")
    public void test01DeployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken067.sol";
        String contractName = "transferTokenContract";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, " + "and not existed tokenId, deploy receive contract")
    public void test02DeployRevContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balance is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken067.sol";
        String contractName = "Result";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String recieveTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 1000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(recieveTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy receive failed with message: " + infoById.get().getResMessage());
        }
        // after deploy, check account resource
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        resultContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(resultContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, " + "and not existed tokenId, trigger transfer contract")
    public void test03TriggerContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long receivereplacedetBefore = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + receivereplacedetBefore);
        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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        TransactionInfo transactionInfo = infoById.get();
        logger.info("the value: " + PublicMethed.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(tokenId, msgId.toString());
        replacedert.replacedertEquals(tokenValue, msgTokenValue);
        replacedert.replacedertEquals(callValue, msgCallValue);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        Long transferreplacedetAfter = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", transferreplacedetAfter is " + transferreplacedetAfter);
        Long receivereplacedetAfter = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", receivereplacedetAfter is " + receivereplacedetAfter);
        replacedert.replacedertEquals(receivereplacedetAfter - receivereplacedetBefore, transferreplacedetBefore + 2L - transferreplacedetAfter);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, " + "and not existed tokenId, get tokenBalance")
    public void test04TriggerTokenBalanceContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 1000_000_000L, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        logger.info("before trigger, dev entropy limit is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, dev entropy usage is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, dev balance is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, user entropy limit is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, user entropy usage is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, user balance is " + Long.toString(userBalanceBefore));
        String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenBalnce(address,vrcToken)", param, false, 0, 1000000000L, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        if (infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("the receivercontract token: " + ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()));
        Long replacedetIssueCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("the receivercontract token(getaccount): " + replacedetIssueCount);
        replacedert.replacedertTrue(replacedetIssueCount == ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken066.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken066 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private byte[] resultContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, deploy transferContract")
    public void test01DeployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken066.sol";
        String contractName = "transferTokenContract";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropy total is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, deploy receive contract")
    public void test02DeployRevContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balance is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken066.sol";
        String contractName = "Result";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String recieveTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 1000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(recieveTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy receive failed with message: " + infoById.get().getResMessage());
        }
        resultContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(resultContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        // after deploy, check account resource
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, trigger transferContract")
    public void test03TriggerContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long receivereplacedetBefore = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + receivereplacedetBefore);
        String tokenId = replacedetAccountId.toStringUtf8();
        Long tokenValue = Long.valueOf(0);
        Long callValue = Long.valueOf(0);
        String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId;
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        TransactionInfo transactionInfo = infoById.get();
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("the value: " + PublicMethed.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(tokenId, msgId.toString());
        replacedert.replacedertEquals(tokenValue, msgTokenValue);
        replacedert.replacedertEquals(callValue, msgCallValue);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        Long transferreplacedetAfter = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", transferreplacedetAfter is " + transferreplacedetAfter);
        Long receivereplacedetAfter = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", receivereplacedetAfter is " + receivereplacedetAfter);
        replacedert.replacedertEquals(receivereplacedetAfter - receivereplacedetBefore, transferreplacedetBefore + 2L - transferreplacedetAfter);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue, get contract tokenBalance")
    public void test04TriggerTokenBalanceContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 1000_000_000L, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        logger.info("before trigger, dev entropy limit is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, dev entropy usage is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, dev balance is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, user entropy limit is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, user entropy usage is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, user balance is " + Long.toString(userBalanceBefore));
        String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenBalnce(address,vrcToken)", param, false, 0, 1000000000L, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        logger.info("the receivercontract token: " + ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()));
        Long replacedetIssueCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("the receivercontract token(getaccount): " + replacedetIssueCount);
        replacedert.replacedertTrue(replacedetIssueCount == ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken064.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken064 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private static ByteString replacedetAccountUser = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private byte[] resultContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue and " + "tokenId in exception condition, deploy transfer contract")
    public void test01DeployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        start = System.currentTimeMillis() + 2000;
        end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(user001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountUser = PublicMethed.queryAccount(user001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The replacedetAccountUser token name: " + tokenName);
        logger.info("The replacedetAccountUser token ID: " + replacedetAccountUser.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken064.sol";
        String contractName = "transferTokenContract";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue and " + "tokenId in exception condition, deploy receiver contract")
    public void test02DeployRevContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balance is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken064.sol";
        String contractName = "Result";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String recieveTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 1000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(recieveTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy receive failed with message: " + infoById.get().getResMessage());
        }
        resultContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(resultContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        // after deploy, check account resource
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with 0 tokenValue and " + "tokenId in exception condition, trigger contract")
    public void test03TriggerContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long receivereplacedetBefore = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + receivereplacedetBefore);
        Long callValue = Long.valueOf(0);
        String param = "\"" + Base58.encode58Check(resultContractAddress) + "\"";
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestValue0IdBigInteger(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info(infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", // replacedert.replacedertEquals("BigInteger out of long range",
        infoById.get().getResMessage().toStringUtf8());
        // transfer to a normal account
        param = "\"" + Base58.encode58Check(dev001Address) + "\"";
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestValue0IdBigInteger(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        // replacedert.replacedertEquals("BigInteger out of long range",
        replacedert.replacedertEquals("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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        callValue = Long.valueOf(0);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\"";
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestValueMaxLong(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // transfer to a normal account
        param = "\"" + Base58.encode58Check(dev001Address) + "\"";
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestValueMaxLong(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        Long transferreplacedetAfter = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", transferreplacedetAfter is " + transferreplacedetAfter);
        Long receivereplacedetAfter = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", receivereplacedetAfter is " + receivereplacedetAfter);
        replacedert.replacedertEquals(receivereplacedetAfter, receivereplacedetBefore);
        replacedert.replacedertEquals(transferreplacedetBefore, transferreplacedetAfter);
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken061.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken061 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "DeployContract with 0 tokenValue and not existed tokenId")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken061.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        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 = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        // get and verify the msg.value and msg.id
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getResultInCon()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("The msg value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken060.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken060 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
    }

    @Test(enabled = true, description = "DeployContract with 0 tokenValue")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken060.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 0;
        long callValue = 5;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(tokenValue), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(tokenValue), contractreplacedetCount);
        // get and verify the msg.value and msg.id
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getResultInCon()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("The msg value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken055.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken055 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    /**
     * constructor.
     */
    @Test(enabled = true, description = "Trigger TransferToken with 0 tokenId," + " and not existed tokenValue")
    public void triggerTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken055.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 200;
        long callValue = 0;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(200), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(200), contractreplacedetCount);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        PublicMethed.sendcoin(transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        tokenId = Long.toString(Long.MAX_VALUE);
        tokenValue = 0;
        callValue = 5;
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "msgTokenValueAndTokenIdTest()", "", false, callValue, 1000000000L, tokenId, tokenValue, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("the value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken054.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken054 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "Trigger transferToken with 0 tokenValue")
    public void testTriggerTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        // String contractName = "transferTokenContract";
        String filePath = "./src/test/resources/soliditycode/contractVrcToken054.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String tokenId = replacedetAccountId.toStringUtf8();
        long tokenValue = 200;
        long callValue = 0;
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        replacedert.replacedertFalse(PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(200), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(200), contractreplacedetCount);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        PublicMethed.sendcoin(transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        tokenId = replacedetAccountId.toStringUtf8();
        tokenValue = 0;
        callValue = 5;
        String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (triggerTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("transaction failed with message: " + infoById.get().getResMessage());
        }
        logger.info("the value: " + PublicMethed.getStrings(infoById.get().getContractResult(0).toByteArray()));
        List<String> retList = PublicMethed.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);
        logger.info("msgCallValue: " + msgCallValue);
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitAfter = accountResource.getEntropyLimit();
        long devEntropyUsageAfter = accountResource.getEntropyUsed();
        long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("after trigger, devEntropyLimitAfter is " + Long.toString(devEntropyLimitAfter));
        logger.info("after trigger, devEntropyUsageAfter is " + Long.toString(devEntropyUsageAfter));
        logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitAfter = accountResource.getEntropyLimit();
        long userEntropyUsageAfter = accountResource.getEntropyUsed();
        long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("after trigger, userEntropyLimitAfter is " + Long.toString(userEntropyLimitAfter));
        logger.info("after trigger, userEntropyUsageAfter is " + Long.toString(userEntropyUsageAfter));
        logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));
        replacedert.replacedertEquals(msgId.toString(), tokenId);
        replacedert.replacedertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue));
        replacedert.replacedertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue));
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken052.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken052 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "TransferToken to contract address tokenID is 0")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 6048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        // devAddress transfer token to A
        PublicMethed.transferreplacedet(dev001Address, replacedetAccountId.toByteArray(), 101, user001Address, user001Key, blockingStubFull);
        // deploy transferTokenContract
        String filePath = "./src/test/resources/soliditycode/contractVrcToken052.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] transferTokenContractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, 10000, replacedetAccountId.toStringUtf8(), 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertFalse(PublicMethed.sendcoin(transferTokenContractAddress, 2048000000, fromAddress, testKey002, blockingStubFull));
        /*// devAddress transfer token to userAddress
    PublicMethed
        .transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100,
            user001Address,
            user001Key,
            blockingStubFull);*/
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        info = PublicMethed.queryAccount(user001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        final Long beforetransferTokenContractAddressBalance = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        final Long beforeDevBalance = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueCount);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueDev:" + beforereplacedetIssueDev);
        String fakereplacedetAccountId = Long.toString(0L);
        String param = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\"," + fakereplacedetAccountId + ",\"1\"";
        // user trigger A to transfer token to B
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "TransferTokenTo(address,vrcToken,uint256)", param, false, 0, 100000000L, "0", 0, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(user001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        final Long aftertransferTokenContractAddressBalance = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        final Long afterDevBalance = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueCount);
        logger.info("afterreplacedetIssueContractAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueDev:" + afterreplacedetIssueDev);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        Long fee = infoById.get().getFee();
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertEquals(beforetransferTokenContractAddressBalance, aftertransferTokenContractAddressBalance);
        replacedert.replacedertEquals(beforeDevBalance, afterDevBalance);
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertEquals(beforereplacedetIssueContractAddress, afterreplacedetIssueContractAddress);
        replacedert.replacedertEquals(beforereplacedetIssueDev, afterreplacedetIssueDev);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken051.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken051 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "TransferToken to contract developer tokenID is 0")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 6048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        // devAddress transfer token to A
        PublicMethed.transferreplacedet(dev001Address, replacedetAccountId.toByteArray(), 101, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // deploy transferTokenContract
        String filePath = "./src/test/resources/soliditycode/contractVrcToken051.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] transferTokenContractAddress;
        String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 10000, replacedetAccountId.toStringUtf8(), 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        logger.info("Deploy entropy total is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertFalse(PublicMethed.sendcoin(transferTokenContractAddress, 2048000000, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        /*// devAddress transfer token to userAddress
    PublicMethed
        .transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100,
            user001Address,
            user001Key,
            blockingStubFull);
    PublicMethed.waitProduceNextBlock(blockingStubFull);*/
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        info = PublicMethed.queryAccount(user001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforetransferTokenContractAddressBalance = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long beforeDevBalance = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueCount);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueDev:" + beforereplacedetIssueDev);
        String fakereplacedetAccountId = Long.toString(0L);
        String param = "\"" + Base58.encode58Check(dev001Address) + "\"," + fakereplacedetAccountId + ",\"1\"";
        // user trigger A to transfer token to B
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "TransferTokenTo(address,vrcToken,uint256)", param, false, 0, 100000000L, "0", 0, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(user001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long aftertransferTokenContractAddressBalance = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long afterDevBalance = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueCount);
        logger.info("afterreplacedetIssueContractAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueDev:" + afterreplacedetIssueDev);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertFalse(infoById.get().getResultValue() == 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertEquals(beforereplacedetIssueContractAddress, afterreplacedetIssueContractAddress);
        replacedert.replacedertEquals(beforereplacedetIssueDev, afterreplacedetIssueDev);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken050.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken050 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    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 Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "TransferToken to contract address ")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        // devAddress transfer token to A
        PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 101, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // deploy transferTokenContract
        String filePath = "./src/test/resources/soliditycode/contractVrcToken050.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] transferTokenContractAddress;
        String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 10000, replacedetAccountId.toStringUtf8(), 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        // devAddress transfer token to userAddress
        PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        info = PublicMethed.queryAccount(user001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        final Long beforereplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueCount);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueDev:" + beforereplacedetIssueDev);
        // user trigger A to transfer token to B
        String param = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\",\"" + replacedetAccountId.toStringUtf8() + "\",\"1\"";
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "TransferTokenTo(address,vrcToken,uint256)", param, false, 0, 100000000L, "0", 0, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(user001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        final Long afterreplacedetIssueDev = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueCount);
        logger.info("afterreplacedetIssueContractAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueDev:" + afterreplacedetIssueDev);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertTrue(beforereplacedetIssueContractAddress == afterreplacedetIssueContractAddress);
        replacedert.replacedertEquals(beforereplacedetIssueDev, afterreplacedetIssueDev);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken048.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken048 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    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 Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "TransferToken msg.value msg,tokenvalue is negative number")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        ByteString replacedetAccountDev = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        final ByteString fakereplacedetAccountId = ByteString.copyFromUtf8(Long.toString(Long.valueOf(replacedetAccountDev.toStringUtf8()) + 100));
        // devAddress transfer token to A
        PublicMethed.transferreplacedet(dev001Address, replacedetAccountId.toByteArray(), 101, user001Address, user001Key, blockingStubFull);
        // deploy transferTokenContract
        String filePath = "./src/test/resources/soliditycode/contractVrcToken048.sol";
        String contractName = "Test";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] transferTokenContractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, 10000, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // devAddress transfer token to userAddress
        PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        info = PublicMethed.queryAccount(user001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueCount);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        // user trigger A to transfer token to B
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "testMsgTokenValue()", "#", false, 0, 100000000L, fakereplacedetAccountId.toStringUtf8(), -1000, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String triggerTxid1 = PublicMethed.triggerContract(transferTokenContractAddress, "testMsgValue()", "#", false, -1000, 100000000L, "0", 0, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(user001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueCount);
        logger.info("afterreplacedetIssueContractAddress:" + afterreplacedetIssueContractAddress);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Trigger entropy total is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertEquals(beforeBalance, afterBalance);
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertEquals(beforereplacedetIssueContractAddress, afterreplacedetIssueContractAddress);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken043.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken043 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 1000L;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private static ByteString replacedetAccountId = null;

    private static ByteString replacedetAccountUser = null;

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);

    private long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private byte[] transferTokenContractAddress = null;

    private byte[] resultContractAddress = null;

    private String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    private String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    private ECKey ecKey1 = new ECKey(Utils.getRandom());

    private byte[] dev001Address = ecKey1.getAddress();

    private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

    private ECKey ecKey2 = new ECKey(Utils.getRandom());

    private byte[] user001Address = ecKey2.getAddress();

    private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes());

    private ECKey ecKey3 = new ECKey(Utils.getRandom());

    private byte[] user002Address = ecKey3.getAddress();

    private String user002Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes());

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
        PublicMethed.printAddress(dev001Key);
        PublicMethed.printAddress(user001Key);
    }

    @Test(enabled = true, description = "TransferToken with invalid tokenId, deploy transferContract")
    public void test01DeployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(user002Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        logger.info("The token name: " + tokenName);
        logger.info("The token ID: " + replacedetAccountId.toStringUtf8());
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balanceBefore is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken043.sol";
        String contractName = "transferTokenContract";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        String transferTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(transferTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (transferTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy transaction failed with message: " + infoById.get().getResMessage());
        }
        transferTokenContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(transferTokenContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with invalid tokenId, deploy receive contract")
    public void test02DeployRevContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // before deploy, check account resource
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long entropyLimit = accountResource.getEntropyLimit();
        long entropyUsage = accountResource.getEntropyUsed();
        long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountBefore = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("before entropyLimit is " + Long.toString(entropyLimit));
        logger.info("before entropyUsage is " + Long.toString(entropyUsage));
        logger.info("before balance is " + Long.toString(balanceBefore));
        logger.info("before replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountBefore: " + devreplacedetCountBefore);
        String filePath = "./src/test/resources/soliditycode/contractVrcToken043.sol";
        String contractName = "Result";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        final String recieveTokenTxid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, 1000, replacedetAccountId.toStringUtf8(), 100, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // after deploy, check account resource
        accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        entropyLimit = accountResource.getEntropyLimit();
        entropyUsage = accountResource.getEntropyUsed();
        long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance();
        Long devreplacedetCountAfter = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        logger.info("after entropyLimit is " + Long.toString(entropyLimit));
        logger.info("after entropyUsage is " + Long.toString(entropyUsage));
        logger.info("after balanceAfter is " + Long.toString(balanceAfter));
        logger.info("after replacedetId: " + replacedetAccountId.toStringUtf8() + ", devreplacedetCountAfter: " + devreplacedetCountAfter);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(recieveTokenTxid, blockingStubFull);
        logger.info("Deploy entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) {
            replacedert.fail("deploy receive failed with message: " + infoById.get().getResMessage());
        }
        resultContractAddress = infoById.get().getContractAddress().toByteArray();
        SmartContract smartContract = PublicMethed.getContract(resultContractAddress, blockingStubFull);
        replacedert.replacedertNotNull(smartContract.getAbi());
        Long contractreplacedetCount = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("Contract has replacedetId: " + replacedetAccountId.toStringUtf8() + ", Count: " + contractreplacedetCount);
        replacedert.replacedertEquals(Long.valueOf(100), Long.valueOf(devreplacedetCountBefore - devreplacedetCountAfter));
        replacedert.replacedertEquals(Long.valueOf(100), contractreplacedetCount);
    }

    @Test(enabled = true, description = "TransferToken with invalid tokenId, transferToken")
    public void test03TriggerContract() {
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user001Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.transferreplacedet(user002Address, replacedetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        long devEntropyLimitBefore = accountResource.getEntropyLimit();
        long devEntropyUsageBefore = accountResource.getEntropyUsed();
        long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance();
        logger.info("before trigger, devEntropyLimitBefore is " + Long.toString(devEntropyLimitBefore));
        logger.info("before trigger, devEntropyUsageBefore is " + Long.toString(devEntropyUsageBefore));
        logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore));
        accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        long userEntropyLimitBefore = accountResource.getEntropyLimit();
        long userEntropyUsageBefore = accountResource.getEntropyUsed();
        long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("before trigger, userEntropyLimitBefore is " + Long.toString(userEntropyLimitBefore));
        logger.info("before trigger, userEntropyUsageBefore is " + Long.toString(userEntropyUsageBefore));
        logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));
        Long transferreplacedetBefore = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + transferreplacedetBefore);
        Long receivereplacedetBefore = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("before trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", Count is " + receivereplacedetBefore);
        // 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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        logger.info("Triger entropytotal is " + infoById.get().getReceipt().getEntropyUsageTotal());
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenId is -1
        tokenId = Long.toString(-1);
        tokenValue = Long.valueOf(1);
        callValue = Long.valueOf(0);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        // replacedert.replacedertEquals("validateForSmartContract failure, not valid token id",
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenId is 1
        tokenId = Long.toString(Long.MIN_VALUE);
        tokenValue = Long.valueOf(1);
        callValue = Long.valueOf(0);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // 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 = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        // tokenId is 0, contract not have vs
        tokenId = Long.toString(0);
        tokenValue = Long.valueOf(1);
        callValue = Long.valueOf(0);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull));
        // tokenId is 0, account does not have vs
        param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user002Address, user002Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user002Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertFalse(PublicMethed.sendcoin(transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user002Address, 5000000, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenId is 0, transfer contract has vs transfer to a contract
        tokenId = Long.toString(0);
        tokenValue = Long.valueOf(1);
        callValue = Long.valueOf(1);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user002Address, user002Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user002Address, user002Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user002Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenId is 0, transfer contract has vs, transfer to normal account
        tokenId = Long.toString(0);
        tokenValue = Long.valueOf(1);
        callValue = Long.valueOf(1);
        param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId;
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTest(address,uint256,vrcToken)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user002Address, user002Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user002Address, user002Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user002Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenid bigger than long.max, trigger to a contract
        callValue = Long.valueOf(0);
        param = "\"" + Base58.encode58Check(resultContractAddress) + "\"";
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestIDOverBigInteger(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user002Address, user002Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        replacedert.replacedertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user002Address, user002Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user002Address), testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // tokenid bigger than long.max, trigger to a normal account
        param = "\"" + Base58.encode58Check(dev001Address) + "\"";
        triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenTestIDOverBigInteger(address)", param, false, callValue, 1000000000L, replacedetAccountId.toStringUtf8(), 2, user002Address, user002Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() != 0);
        replacedert.replacedertEquals(FAILED, infoById.get().getResult());
        replacedert.replacedertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8());
        Long transferreplacedetAfter = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, transferTokenContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", transferreplacedetAfter is " + transferreplacedetAfter);
        Long receivereplacedetAfter = PublicMethed.getreplacedetIssueValue(resultContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("after trigger, resultContractAddress has replacedetId " + replacedetAccountId.toStringUtf8() + ", receivereplacedetAfter is " + receivereplacedetAfter);
        replacedert.replacedertEquals(receivereplacedetAfter, receivereplacedetBefore);
        replacedert.replacedertEquals(transferreplacedetBefore, transferreplacedetAfter);
        // unfreeze resource
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, user002Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken041.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken041 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private ManagedChannel channelFull1 = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    private static int randomInt(int minInt, int maxInt) {
        return (int) Math.round(Math.random() * (maxInt - minInt) + minInt);
    }

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "Trigger contract msg.tokenId add 1,msg.tokenValue add 1")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        ByteString replacedetAccountDev = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        final ByteString fakeTokenId = ByteString.copyFromUtf8(Long.toString(Long.valueOf(replacedetAccountDev.toStringUtf8()) + 100));
        // devAddress transfer token to A
        PublicMethed.transferreplacedet(dev001Address, replacedetAccountId.toByteArray(), 101, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // deploy transferTokenContract
        String filePath = "src/test/resources/soliditycode/contractVrcToken041.sol";
        String contractName = "tokenTest";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] transferTokenContractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, 10000, replacedetAccountId.toStringUtf8(), 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // devAddress transfer token to userAddress
        PublicMethed.transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        info = PublicMethed.queryAccount(user001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueCount);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        // user trigger A to transfer token to B
        String param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + fakeTokenId.toStringUtf8() + "\",\"105\"";
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "TransferTokenTo(address,vrcToken,uint256)", param, false, 0, 100000000L, fakeTokenId.toStringUtf8(), 10000000L, user001Address, user001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(user001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(user001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueCount = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueCount);
        logger.info("afterreplacedetIssueContractAddress:" + afterreplacedetIssueContractAddress);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertEquals(beforeBalance, afterBalance);
        replacedert.replacedertEquals(beforereplacedetIssueCount, afterreplacedetIssueCount);
        replacedert.replacedertEquals(beforereplacedetIssueContractAddress, afterreplacedetIssueContractAddress);
        replacedert.replacedertTrue(afterEntropyUsed == 0L);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken039.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken039 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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[] proxyTestAddress;

    byte[] atestAddress;

    byte[] btestAddress;

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "Deploy Proxy contract")
    public void deploy01TransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("dev001Address:" + Base58.encode58Check(dev001Address));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("user001Address:" + Base58.encode58Check(user001Address));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // deploy transferTokenContract
        int originEntropyLimit = 50000;
        String filePath = "src/test/resources/soliditycode/contractVrcToken039.sol";
        String contractName = "Proxy";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        proxyTestAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 1000L, 0, originEntropyLimit, replacedetAccountId.toStringUtf8(), 1000, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String contractName1 = "A";
        HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1);
        String code1 = retMap1.get("byteCode").toString();
        String abi1 = retMap1.get("abI").toString();
        atestAddress = PublicMethed.deployContract(contractName1, abi1, code1, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String contractName2 = "B";
        HashMap retMap2 = PublicMethed.getBycodeAbi(filePath, contractName2);
        String code2 = retMap2.get("byteCode").toString();
        String abi2 = retMap2.get("abI").toString();
        btestAddress = PublicMethed.deployContract(contractName2, abi2, code2, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // devAddress transfer token to userAddress
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = true, description = "Trigger Proxy contract use AddressA")
    public void deploy02TransferTokenContract() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(proxyTestAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueAAddress = PublicMethed.getreplacedetIssueValue(atestAddress, replacedetAccountId, blockingStubFull);
        Long beforeBalanceContractAddress = PublicMethed.queryAccount(proxyTestAddress, blockingStubFull).getBalance();
        Long beforeUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueBAddress:" + beforereplacedetIssueBAddress);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress);
        logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress);
        logger.info("beforeUserBalance:" + beforeUserBalance);
        String param = "\"" + Base58.encode58Check(atestAddress) + "\"";
        String param1 = "\"" + "1" + "\",\"" + Base58.encode58Check(user001Address) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        String triggerTxid = PublicMethed.triggerContract(proxyTestAddress, "upgradeTo(address)", param, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        final String triggerTxid1 = PublicMethed.triggerContract(proxyTestAddress, "trans(uint256,address,vrcToken)", param1, false, 0, 1000000000L, replacedetAccountId.toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(proxyTestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueAAddress = PublicMethed.getreplacedetIssueValue(atestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterBalanceContractAddress = PublicMethed.queryAccount(proxyTestAddress, blockingStubFull).getBalance();
        Long afterUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueDevAddress);
        logger.info("afterreplacedetIssueDevAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueBAddress:" + afterreplacedetIssueBAddress);
        logger.info("afterreplacedetIssueUserAddress:" + afterreplacedetIssueUserAddress);
        logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress);
        logger.info("afterUserBalance:" + afterUserBalance);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid1, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress == beforereplacedetIssueUserAddress);
        replacedert.replacedertTrue(afterBalanceContractAddress == beforeBalanceContractAddress - 1);
        replacedert.replacedertTrue(afterreplacedetIssueContractAddress == beforereplacedetIssueContractAddress + 1);
        replacedert.replacedertTrue(afterreplacedetIssueDevAddress == beforereplacedetIssueDevAddress - 1);
        replacedert.replacedertTrue(afterUserBalance == beforeUserBalance + 1);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress == afterreplacedetIssueUserAddress);
        replacedert.replacedertTrue(afterreplacedetIssueBAddress == beforereplacedetIssueBAddress);
    }

    @Test(enabled = true, description = "Trigger Proxy contract use AddressB")
    public void deploy03TransferTokenContract() {
        Account info1;
        AccountResourceMessage resourceInfo1 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info1 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance1 = info1.getBalance();
        Long beforeEntropyUsed1 = resourceInfo1.getEntropyUsed();
        Long beforePhotonUsed1 = resourceInfo1.getPhotonUsed();
        Long beforeFreePhotonUsed1 = resourceInfo1.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress1 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress1 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress1 = PublicMethed.getreplacedetIssueValue(proxyTestAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueBAddress1 = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long beforeBalanceContractAddress1 = PublicMethed.queryAccount(proxyTestAddress, blockingStubFull).getBalance();
        Long beforeUserBalance1 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance1:" + beforeBalance1);
        logger.info("beforeEntropyUsed1:" + beforeEntropyUsed1);
        logger.info("beforePhotonUsed1:" + beforePhotonUsed1);
        logger.info("beforeFreePhotonUsed1:" + beforeFreePhotonUsed1);
        logger.info("beforereplacedetIssueContractAddress1:" + beforereplacedetIssueContractAddress1);
        logger.info("beforereplacedetIssueBAddress1:" + beforereplacedetIssueBAddress1);
        logger.info("beforereplacedetIssueDevAddress1:" + beforereplacedetIssueDevAddress1);
        logger.info("beforereplacedetIssueUserAddress1:" + beforereplacedetIssueUserAddress1);
        logger.info("beforeBalanceContractAddress1:" + beforeBalanceContractAddress1);
        logger.info("beforeUserBalance1:" + beforeUserBalance1);
        String param3 = "\"" + Base58.encode58Check(btestAddress) + "\"";
        String param2 = "\"" + "1" + "\",\"" + Base58.encode58Check(user001Address) + "\",\"" + replacedetAccountId.toStringUtf8() + "\"";
        String triggerTxid2 = PublicMethed.triggerContract(proxyTestAddress, "upgradeTo(address)", param3, false, 0, 1000000000L, replacedetAccountId.toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull);
        String triggerTxid3 = PublicMethed.triggerContract(proxyTestAddress, "trans(uint256,address,vrcToken)", param2, false, 0, 1000000000L, replacedetAccountId.toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull);
        Account infoafter1 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance1 = infoafter1.getBalance();
        Long afterEntropyUsed1 = resourceInfoafter1.getEntropyUsed();
        Long afterreplacedetIssueDevAddress1 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed1 = resourceInfoafter1.getPhotonUsed();
        Long afterFreePhotonUsed1 = resourceInfoafter1.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress1 = PublicMethed.getreplacedetIssueValue(proxyTestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueBAddress1 = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress1 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterBalanceContractAddress1 = PublicMethed.queryAccount(proxyTestAddress, blockingStubFull).getBalance();
        Long afterUserBalance1 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance1:" + afterBalance1);
        logger.info("afterEntropyUsed1:" + afterEntropyUsed1);
        logger.info("afterPhotonUsed1:" + afterPhotonUsed1);
        logger.info("afterFreePhotonUsed1:" + afterFreePhotonUsed1);
        logger.info("afterreplacedetIssueCount1:" + afterreplacedetIssueDevAddress1);
        logger.info("afterreplacedetIssueDevAddress1:" + afterreplacedetIssueContractAddress1);
        logger.info("afterreplacedetIssueBAddress1:" + afterreplacedetIssueBAddress1);
        logger.info("afterreplacedetIssueUserAddress1:" + afterreplacedetIssueUserAddress1);
        logger.info("afterBalanceContractAddress1:" + afterBalanceContractAddress1);
        logger.info("afterUserBalance1:" + afterUserBalance1);
        Optional<TransactionInfo> infoById2 = PublicMethed.getTransactionInfoById(triggerTxid3, blockingStubFull);
        replacedert.replacedertTrue(infoById2.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress1 == beforereplacedetIssueUserAddress1);
        replacedert.replacedertTrue(afterBalanceContractAddress1 == beforeBalanceContractAddress1 - 1);
        replacedert.replacedertTrue(afterreplacedetIssueContractAddress1 == beforereplacedetIssueContractAddress1 + 1);
        replacedert.replacedertTrue(afterreplacedetIssueDevAddress1 == beforereplacedetIssueDevAddress1 - 1);
        replacedert.replacedertTrue(afterUserBalance1 == beforeUserBalance1 + 1);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress1 == afterreplacedetIssueUserAddress1);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken038.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken038 {

    private static final long TotalSupply = 10000000L;

    private static final long now = System.currentTimeMillis();

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key1");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "Multi-level call transferToken replacedert tokenBalance ")
    public void deployTransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("dev001Address:" + Base58.encode58Check(dev001Address));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("user001Address:" + Base58.encode58Check(user001Address));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 3, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 3, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertFalse(replacedetAccountId.toStringUtf8().equals(""));
        // deploy transferTokenContract
        int originEntropyLimit = 50000;
        String filePath = "src/test/resources/soliditycode/contractVrcToken038.sol";
        String contractName2 = "transferVrc10";
        HashMap retMap2 = PublicMethed.getBycodeAbi(filePath, contractName2);
        String code2 = retMap2.get("byteCode").toString();
        String abi2 = retMap2.get("abI").toString();
        final byte[] transferTokenContractAddress = PublicMethed.deployContract(contractName2, abi2, code2, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        String contractName = "receiveVrc10";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] btestAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedert.replacedertFalse(PublicMethed.sendcoin(transferTokenContractAddress, 1000000000L, fromAddress, testKey002, blockingStubFull));
        replacedert.replacedertFalse(PublicMethed.sendcoin(btestAddress, 1000000000L, fromAddress, testKey002, blockingStubFull));
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long beforeBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long beforeUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueBAddress:" + beforereplacedetIssueBAddress);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress);
        logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress);
        logger.info("beforeUserBalance:" + beforeUserBalance);
        String param = "\"" + Base58.encode58Check(btestAddress) + "\"";
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "receive(address)", param, false, 0, 1000000000L, replacedetAccountId.toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long afterUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueDevAddress);
        logger.info("afterreplacedetIssueDevAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueBAddress:" + afterreplacedetIssueBAddress);
        logger.info("afterreplacedetIssueUserAddress:" + afterreplacedetIssueUserAddress);
        logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress);
        logger.info("afterUserBalance:" + afterUserBalance);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 1);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress == beforereplacedetIssueUserAddress);
        replacedert.replacedertEquals(afterBalanceContractAddress, beforeBalanceContractAddress);
        replacedert.replacedertTrue(afterreplacedetIssueContractAddress == beforereplacedetIssueContractAddress);
        replacedert.replacedertTrue(afterreplacedetIssueBAddress == beforereplacedetIssueBAddress);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, null, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken037.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken037 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 10000000L;

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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 ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = true, description = "Multi-level call transferToken tokenBalance")
    public void deploy01TransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("dev001Address:" + Base58.encode58Check(dev001Address));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("user001Address:" + Base58.encode58Check(user001Address));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        // deploy transferTokenContract
        int originEntropyLimit = 50000;
        String filePath = "src/test/resources/soliditycode/contractVrcToken037.sol";
        String contractName = "receiveVrc10";
        HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        String code = retMap.get("byteCode").toString();
        String abi = retMap.get("abI").toString();
        byte[] btestAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        String contractName1 = "transferVrc10";
        HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1);
        String code1 = retMap1.get("byteCode").toString();
        String abi1 = retMap1.get("abI").toString();
        byte[] transferTokenContractAddress = PublicMethed.deployContract(contractName1, abi1, code1, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long beforeBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long beforeUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueContractAddress:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueBAddress:" + beforereplacedetIssueBAddress);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress);
        logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress);
        logger.info("beforeUserBalance:" + beforeUserBalance);
        String param = "\"" + Base58.encode58Check(btestAddress) + "\"";
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "receive(address)", param, false, 0, 1000000000L, replacedetAccountId.toStringUtf8(), 10, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueBAddress = PublicMethed.getreplacedetIssueValue(btestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afterBalanceContractAddress = PublicMethed.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance();
        Long afterUserBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueDevAddress);
        logger.info("afterreplacedetIssueDevAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueBAddress:" + afterreplacedetIssueBAddress);
        logger.info("afterreplacedetIssueUserAddress:" + afterreplacedetIssueUserAddress);
        logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress);
        logger.info("afterUserBalance:" + afterUserBalance);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(afterreplacedetIssueUserAddress == beforereplacedetIssueUserAddress);
        replacedert.replacedertEquals(afterBalanceContractAddress, beforeBalanceContractAddress);
        replacedert.replacedertTrue(afterreplacedetIssueDevAddress == beforereplacedetIssueDevAddress - 10);
        replacedert.replacedertTrue(afterreplacedetIssueBAddress == beforereplacedetIssueBAddress + 10);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

19 Source : ContractVrcToken036.java
with GNU Lesser General Public License v3.0
from vision-consensus

@Slf4j
public clreplaced ContractVrcToken036 {

    private static final long now = System.currentTimeMillis();

    private static final long TotalSupply = 10000000L;

    private static ByteString replacedetAccountId = null;

    private static String tokenName = "testreplacedetIssue_" + Long.toString(now);

    private final String testKey002 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2");

    private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);

    byte[] transferTokenContractAddress;

    String description = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetDescription");

    String url = Configuration.getByPath("testng.conf").getString("defaultParameter.replacedetUrl");

    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());

    int originEntropyLimit = 50000;

    byte[] transferTokenWithPureTestAddress;

    private ManagedChannel channelFull = null;

    private WalletGrpc.WalletBlockingStub blockingStubFull = null;

    private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);

    private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit");

    @BeforeSuite
    public void beforeSuite() {
        Wallet wallet = new Wallet();
        Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
    }

    /**
     * constructor.
     */
    @BeforeClreplaced(enabled = true)
    public void beforeClreplaced() {
        channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true).build();
        blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
    }

    @Test(enabled = false, description = "Deploy contract")
    public void deploy01TransferTokenContract() {
        replacedert.replacedertTrue(PublicMethed.sendcoin(dev001Address, 9999000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("dev001Address:" + Base58.encode58Check(dev001Address));
        replacedert.replacedertTrue(PublicMethed.sendcoin(user001Address, 4048000000L, fromAddress, testKey002, blockingStubFull));
        logger.info("user001Address:" + Base58.encode58Check(user001Address));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // freeze balance
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull));
        replacedert.replacedertTrue(PublicMethed.freezeBalanceGetEntropy(user001Address, 2048000000, 0, 1, user001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        long start = System.currentTimeMillis() + 2000;
        long end = System.currentTimeMillis() + 1000000000;
        // Create a new replacedetIssue success.
        replacedert.replacedertTrue(PublicMethed.createreplacedetIssue(dev001Address, tokenName, TotalSupply, 1, 100, start, end, 1, description, url, 10000L, 10000L, 1L, 1L, dev001Key, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        replacedetAccountId = PublicMethed.queryAccount(dev001Address, blockingStubFull).getreplacedetIssuedID();
        // deploy transferTokenContract
        // String filePath = "src/test/resources/soliditycode/contractVrcToken036.sol";
        // String contractName = "IllegalDecorate";
        // HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
        // String code = retMap.get("byteCode").toString();
        // String abi = retMap.get("abI").toString();
        // transferTokenContractAddress = PublicMethed
        // .deployContract(contractName, abi, code, "", maxFeeLimit,
        // 0L, 0, originEntropyLimit, "0",
        // 0, null, dev001Key, dev001Address,
        // blockingStubFull);
        // PublicMethed.waitProduceNextBlock(blockingStubFull);
        // PublicMethed.waitProduceNextBlock(blockingStubFull);
        // 
        // // devAddress transfer token to userAddress
        // PublicMethed
        // .transferreplacedet(transferTokenContractAddress, replacedetAccountId.toByteArray(), 100,
        // dev001Address,
        // dev001Key,
        // blockingStubFull);
        // replacedert
        // .replacedertTrue(PublicMethed.sendcoin(transferTokenContractAddress, 100, fromAddress,
        // testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = false, description = "Trigger transferTokenWithPure contract")
    public void deploy02TransferTokenContract() {
        Account info;
        AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance = info.getBalance();
        Long beforeEntropyUsed = resourceInfo.getEntropyUsed();
        Long beforePhotonUsed = resourceInfo.getPhotonUsed();
        Long beforeFreePhotonUsed = resourceInfo.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long user001AddressAddressBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed);
        logger.info("beforePhotonUsed:" + beforePhotonUsed);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueContractAddress);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress);
        logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance);
        // user trigger A to transfer token to B
        String param = "\"" + Base58.encode58Check(user001Address) + "\",\"1\"";
        final String triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "transferTokenWithPure(address,uint256)", param, false, 10, 1000000000L, replacedetAccountId.toStringUtf8(), 10, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance = infoafter.getBalance();
        Long afterEntropyUsed = resourceInfoafter.getEntropyUsed();
        Long afterreplacedetIssueDevAddress = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed = resourceInfoafter.getPhotonUsed();
        Long afterFreePhotonUsed = resourceInfoafter.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afteruser001AddressAddressBalance = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance);
        logger.info("afterEntropyUsed:" + afterEntropyUsed);
        logger.info("afterPhotonUsed:" + afterPhotonUsed);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueDevAddress);
        logger.info("afterreplacedetIssueDevAddress:" + afterreplacedetIssueContractAddress);
        logger.info("afterreplacedetIssueUserAddress:" + afterreplacedetIssueUserAddress);
        logger.info("afterContractAddressBalance:" + afteruser001AddressAddressBalance);
        Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull);
        replacedert.replacedertTrue(infoById.get().getResultValue() == 0);
        replacedert.replacedertTrue(beforereplacedetIssueDevAddress - 10 == afterreplacedetIssueDevAddress);
        replacedert.replacedertTrue(beforereplacedetIssueUserAddress + 10 == afterreplacedetIssueUserAddress);
        replacedert.replacedertTrue(user001AddressAddressBalance + 10 == afteruser001AddressAddressBalance);
        String filePath = "src/test/resources/soliditycode/contractVrcToken036.sol";
        String contractName1 = "IllegalDecorate1";
        HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1);
        String code1 = retMap1.get("byteCode").toString();
        String abi1 = retMap1.get("abI").toString();
        transferTokenWithPureTestAddress = PublicMethed.deployContract(contractName1, abi1, code1, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // devAddress transfer token to userAddress
        PublicMethed.transferreplacedet(transferTokenWithPureTestAddress, replacedetAccountId.toByteArray(), 100, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(transferTokenWithPureTestAddress, 100, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
    }

    @Test(enabled = false, description = "Trigger transferTokenWithConstant contract")
    public void deploy03TransferTokenContract() {
        Account info1;
        AccountResourceMessage resourceInfo1 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info1 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance1 = info1.getBalance();
        Long beforeEntropyUsed1 = resourceInfo1.getEntropyUsed();
        Long beforePhotonUsed1 = resourceInfo1.getPhotonUsed();
        Long beforeFreePhotonUsed1 = resourceInfo1.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress1 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress1 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress1 = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long user001AddressAddressBalance1 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance1);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed1);
        logger.info("beforePhotonUsed:" + beforePhotonUsed1);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed1);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueContractAddress1);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress1);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress1);
        logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance1);
        // user trigger A to transfer token to B
        String param1 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\"";
        final String triggerTxid1 = PublicMethed.triggerContract(transferTokenWithPureTestAddress, "transferTokenWithConstant(address,uint256)", param1, false, 10, 1000000000L, replacedetAccountId.toStringUtf8(), 10, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter1 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance1 = infoafter1.getBalance();
        Long afterEntropyUsed1 = resourceInfoafter1.getEntropyUsed();
        Long afterreplacedetIssueDevAddress1 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed1 = resourceInfoafter1.getPhotonUsed();
        Long afterFreePhotonUsed1 = resourceInfoafter1.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress1 = PublicMethed.getreplacedetIssueValue(transferTokenContractAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress1 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afteruser001AddressAddressBalance1 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterBalance:" + afterBalance1);
        logger.info("afterEntropyUsed:" + afterEntropyUsed1);
        logger.info("afterPhotonUsed:" + afterPhotonUsed1);
        logger.info("afterFreePhotonUsed:" + afterFreePhotonUsed1);
        logger.info("afterreplacedetIssueCount:" + afterreplacedetIssueDevAddress1);
        logger.info("afterreplacedetIssueDevAddress:" + afterreplacedetIssueContractAddress1);
        logger.info("afterreplacedetIssueUserAddress:" + afterreplacedetIssueUserAddress1);
        logger.info("afterContractAddressBalance:" + afteruser001AddressAddressBalance1);
        Optional<TransactionInfo> infoById1 = PublicMethed.getTransactionInfoById(triggerTxid1, blockingStubFull);
        replacedert.replacedertEquals(beforeBalance1, afterBalance1);
        replacedert.replacedertEquals(beforereplacedetIssueDevAddress1, afterreplacedetIssueDevAddress1);
        replacedert.replacedertEquals(beforereplacedetIssueUserAddress1, afterreplacedetIssueUserAddress1);
        replacedert.replacedertEquals(user001AddressAddressBalance1, afteruser001AddressAddressBalance1);
    }

    @Test(enabled = false, description = "Trigger transferTokenWithView contract")
    public void deploy04TransferTokenContract() {
        String filePath2 = "src/test/resources/soliditycode/contractVrcToken036.sol";
        String contractName2 = "IllegalDecorate2";
        HashMap retMap2 = PublicMethed.getBycodeAbi(filePath2, contractName2);
        String code2 = retMap2.get("byteCode").toString();
        String abi2 = retMap2.get("abI").toString();
        byte[] transferTokenWithViewAddress = PublicMethed.deployContract(contractName2, abi2, code2, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        // devAddress transfer token to userAddress
        PublicMethed.transferreplacedet(transferTokenWithViewAddress, replacedetAccountId.toByteArray(), 100, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(transferTokenWithViewAddress, 100, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info2;
        AccountResourceMessage resourceInfo2 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info2 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance2 = info2.getBalance();
        Long beforeEntropyUsed2 = resourceInfo2.getEntropyUsed();
        Long beforePhotonUsed2 = resourceInfo2.getPhotonUsed();
        Long beforeFreePhotonUsed2 = resourceInfo2.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress2 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress2 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress2 = PublicMethed.getreplacedetIssueValue(transferTokenWithViewAddress, replacedetAccountId, blockingStubFull);
        Long user001AddressAddressBalance2 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforereplacedetIssueContractAddress2:" + beforereplacedetIssueContractAddress2);
        logger.info("beforereplacedetIssueDevAddress2:" + beforereplacedetIssueDevAddress2);
        logger.info("beforereplacedetIssueUserAddress2:" + beforereplacedetIssueUserAddress2);
        logger.info("user001AddressAddressBalance2:" + user001AddressAddressBalance2);
        // user trigger A to transfer token to B
        String param2 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\"";
        String triggerTxid2 = PublicMethed.triggerContract(transferTokenWithViewAddress, "transferTokenWithView(address,uint256)", param2, false, 10, 1000000000L, replacedetAccountId.toStringUtf8(), 10, dev001Address, dev001Key, blockingStubFull);
        Account infoafter2 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter2 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance2 = infoafter2.getBalance();
        Long afterEntropyUsed2 = resourceInfoafter2.getEntropyUsed();
        Long afterreplacedetIssueDevAddress2 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed2 = resourceInfoafter2.getPhotonUsed();
        Long afterFreePhotonUsed2 = resourceInfoafter2.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress2 = PublicMethed.getreplacedetIssueValue(transferTokenWithViewAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress2 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afteruser001AddressAddressBalance2 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("afterreplacedetIssueDevAddress2:" + afterreplacedetIssueDevAddress2);
        logger.info("afterreplacedetIssueContractAddress2:" + afterreplacedetIssueContractAddress2);
        logger.info("afterreplacedetIssueUserAddress2:" + afterreplacedetIssueUserAddress2);
        logger.info("afteruser001AddressAddressBalance2:" + afteruser001AddressAddressBalance2);
        Optional<TransactionInfo> infoById2 = PublicMethed.getTransactionInfoById(triggerTxid2, blockingStubFull);
        replacedert.replacedertEquals(beforereplacedetIssueDevAddress2, afterreplacedetIssueDevAddress2);
        replacedert.replacedertEquals(beforereplacedetIssueUserAddress2, afterreplacedetIssueUserAddress2);
        replacedert.replacedertEquals(user001AddressAddressBalance2, afteruser001AddressAddressBalance2);
    }

    @Test(enabled = false, description = "Trigger transferTokenWithNoPayable contract")
    public void deploy05TransferTokenContract() {
        String filePath = "src/test/resources/soliditycode/contractVrcToken036.sol";
        String contractName3 = "IllegalDecorate3";
        HashMap retMap3 = PublicMethed.getBycodeAbi(filePath, contractName3);
        String code3 = retMap3.get("byteCode").toString();
        String abi3 = retMap3.get("abI").toString();
        byte[] transferTokenWithOutPayableTestAddress = PublicMethed.deployContract(contractName3, abi3, code3, "", maxFeeLimit, 0L, 0, originEntropyLimit, "0", 0, null, dev001Key, dev001Address, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        PublicMethed.transferreplacedet(transferTokenWithOutPayableTestAddress, replacedetAccountId.toByteArray(), 100, dev001Address, dev001Key, blockingStubFull);
        replacedert.replacedertTrue(PublicMethed.sendcoin(transferTokenWithOutPayableTestAddress, 100, fromAddress, testKey002, blockingStubFull));
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account info3;
        AccountResourceMessage resourceInfo3 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        info3 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        Long beforeBalance3 = info3.getBalance();
        Long beforeEntropyUsed3 = resourceInfo3.getEntropyUsed();
        Long beforePhotonUsed3 = resourceInfo3.getPhotonUsed();
        Long beforeFreePhotonUsed3 = resourceInfo3.getFreePhotonUsed();
        Long beforereplacedetIssueDevAddress3 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueUserAddress3 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long beforereplacedetIssueContractAddress3 = PublicMethed.getreplacedetIssueValue(transferTokenWithOutPayableTestAddress, replacedetAccountId, blockingStubFull);
        Long user001AddressAddressBalance3 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        logger.info("beforeBalance:" + beforeBalance3);
        logger.info("beforeEntropyUsed:" + beforeEntropyUsed3);
        logger.info("beforePhotonUsed:" + beforePhotonUsed3);
        logger.info("beforeFreePhotonUsed:" + beforeFreePhotonUsed3);
        logger.info("beforereplacedetIssueCount:" + beforereplacedetIssueContractAddress3);
        logger.info("beforereplacedetIssueDevAddress:" + beforereplacedetIssueDevAddress3);
        logger.info("beforereplacedetIssueUserAddress:" + beforereplacedetIssueUserAddress3);
        logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance3);
        String param3 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\"";
        String triggerTxid3 = PublicMethed.triggerContract(transferTokenWithOutPayableTestAddress, "transferTokenWithOutPayable(address,uint256)", param3, false, 10, 1000000000L, replacedetAccountId.toStringUtf8(), 10, dev001Address, dev001Key, blockingStubFull);
        PublicMethed.waitProduceNextBlock(blockingStubFull);
        Account infoafter3 = PublicMethed.queryAccount(dev001Address, blockingStubFull);
        AccountResourceMessage resourceInfoafter3 = PublicMethed.getAccountResource(dev001Address, blockingStubFull);
        Long afterBalance3 = infoafter3.getBalance();
        Long afterEntropyUsed3 = resourceInfoafter3.getEntropyUsed();
        Long afterreplacedetIssueDevAddress3 = PublicMethed.getreplacedetIssueValue(dev001Address, replacedetAccountId, blockingStubFull);
        Long afterPhotonUsed3 = resourceInfoafter3.getPhotonUsed();
        Long afterFreePhotonUsed3 = resourceInfoafter3.getFreePhotonUsed();
        Long afterreplacedetIssueContractAddress3 = PublicMethed.getreplacedetIssueValue(transferTokenWithOutPayableTestAddress, replacedetAccountId, blockingStubFull);
        Long afterreplacedetIssueUserAddress3 = PublicMethed.getreplacedetIssueValue(user001Address, replacedetAccountId, blockingStubFull);
        Long afteruser001AddressAddressBalance3 = PublicMethed.queryAccount(user001Address, blockingStubFull).getBalance();
        Optional<TransactionInfo> infoById3 = PublicMethed.getTransactionInfoById(triggerTxid3, blockingStubFull);
        replacedert.replacedertTrue(infoById3.get().getResultValue() == 1);
        replacedert.replacedertEquals(beforereplacedetIssueDevAddress3, afterreplacedetIssueDevAddress3);
        replacedert.replacedertEquals(beforereplacedetIssueUserAddress3, afterreplacedetIssueUserAddress3);
        replacedert.replacedertEquals(user001AddressAddressBalance3, afteruser001AddressAddressBalance3);
        PublicMethed.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull);
        PublicMethed.unFreezeBalance(user001Address, user001Key, 1, null, blockingStubFull);
    }

    /**
     * constructor.
     */
    @AfterClreplaced
    public void shutdown() throws InterruptedException {
        PublicMethed.freedResource(dev001Address, dev001Key, fromAddress, blockingStubFull);
        PublicMethed.freedResource(user001Address, user001Key, fromAddress, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull);
        PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull);
        if (channelFull != null) {
            channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
        }
    }
}

See More Examples