org.web3j.utils.Convert.Unit Java Examples

The following examples show how to use org.web3j.utils.Convert.Unit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadTimeoutAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void submittingTransactionWithoutNonceReturnsAGatewayTimeoutError() {
  final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00";
  final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact();

  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          recipient,
          transferAmountWei);
  final SignerResponse<JsonRpcErrorResponse> signerResponse =
      ethSigner.transactions().submitExceptional(transaction);
  assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT);
  assertThat(signerResponse.jsonRpc().getError())
      .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT);
}
 
Example #2
Source File: RestrictingScenario.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 *  正常的场景:
 *  初始化账户余额
 *  创建锁仓计划(4000)
 *  获取锁仓信息(4100)
 */
@Test
public void executeScenario() throws Exception {
	//初始化账户余额
	transfer();
	BigInteger restrictingBalance = web3j.platonGetBalance(restrictingSendCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance();
	assertTrue(new BigDecimal(restrictingBalance).compareTo(Convert.fromVon(transferValue, Unit.VON))>=0);
	
	//创建锁仓计划(4000)
	TransactionResponse createRestrictingPlanResponse = createRestrictingPlan();
	assertTrue(createRestrictingPlanResponse.toString(),createRestrictingPlanResponse.isStatusOk());

	//获取锁仓信息(4100)
	CallResponse<RestrictingItem> getRestrictingPlanInfoResponse = getRestrictingPlanInfo();
	assertTrue(getRestrictingPlanInfoResponse.toString(),getRestrictingPlanInfoResponse.isStatusOk());
}
 
Example #3
Source File: SlashScenario.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * 正常的场景:
 * 初始化账户余额
 * 举报双签(3000)
 * 查询节点是否已被举报过多签(3001)
 */
@Test
public void executeScenario() throws Exception {
	//初始化账户余额
	transfer();
	
	BigInteger slashBalance = web3j.platonGetBalance(slashCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance();
	assertTrue(new BigDecimal(slashBalance).compareTo(Convert.fromVon(transferValue, Unit.VON))>=0);
	
	//举报双签(3000)
	BaseResponse reportDuplicateSignResponse = reportDuplicateSign();
	assertTrue(reportDuplicateSignResponse.toString(),reportDuplicateSignResponse.getCode()>=0);
	
	//查询节点是否已被举报过多签(3001)
	BaseResponse checkDuplicateSignResponse = checkDuplicateSign();
	assertTrue(checkDuplicateSignResponse.toString(),checkDuplicateSignResponse.isStatusOk());
	
}
 
Example #4
Source File: Amount.java    From besu with Apache License 2.0 6 votes vote down vote up
public Amount subtract(final Amount subtracting) {

    final Unit denominator;
    if (unit.getWeiFactor().compareTo(subtracting.unit.getWeiFactor()) < 0) {
      denominator = unit;
    } else {
      denominator = subtracting.unit;
    }

    final BigDecimal result =
        Convert.fromWei(
            Convert.toWei(value, unit).subtract(Convert.toWei(subtracting.value, subtracting.unit)),
            denominator);

    return new Amount(result, denominator);
  }
 
Example #5
Source File: ValueTransferAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void valueTransferNonceTooLow() {
  valueTransfer(); // call this test to increment the nonce
  final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact();
  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          BigInteger.ZERO,
          GAS_PRICE,
          INTRINSIC_GAS,
          RECIPIENT,
          transferAmountWei);

  final SignerResponse<JsonRpcErrorResponse> jsonRpcErrorResponseSignerResponse =
      ethSigner().transactions().submitExceptional(transaction);

  assertThat(jsonRpcErrorResponseSignerResponse.jsonRpc().getError())
      .isEqualTo(JsonRpcError.NONCE_TOO_LOW);
}
 
Example #6
Source File: ValueTransferAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleValueTransfers() {
  final BigInteger transferAmountWei = Convert.toWei("1", Unit.ETHER).toBigIntegerExact();
  final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT);
  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          RECIPIENT,
          transferAmountWei);

  String hash = null;
  for (int i = 0; i < FIFTY_TRANSACTIONS; i++) {
    hash = ethSigner().transactions().submit(transaction);
  }
  ethNode().transactions().awaitBlockContaining(hash);

  final BigInteger endBalance = ethNode().accounts().balance(RECIPIENT);
  final BigInteger numberOfTransactions = BigInteger.valueOf(FIFTY_TRANSACTIONS);
  assertThat(endBalance)
      .isEqualTo(startBalance.add(transferAmountWei.multiply(numberOfTransactions)));
}
 
Example #7
Source File: ValueTransferAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void valueTransfer() {
  final BigInteger transferAmountWei = Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact();
  final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT);
  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          RECIPIENT,
          transferAmountWei);

  final String hash = ethSigner().transactions().submit(transaction);
  ethNode().transactions().awaitBlockContaining(hash);

  final BigInteger expectedEndBalance = startBalance.add(transferAmountWei);
  final BigInteger actualEndBalance = ethNode().accounts().balance(RECIPIENT);
  assertThat(actualEndBalance).isEqualTo(expectedEndBalance);
}
 
Example #8
Source File: MultiKeyTransactionSigningAcceptanceTestBase.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
void performTransaction() {
  final BigInteger transferAmountWei = Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact();

  final BigInteger startBalance = ethNode.accounts().balance(RECIPIENT);
  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          RECIPIENT,
          transferAmountWei);

  final String hash = ethSigner.transactions().submit(transaction);
  ethNode.transactions().awaitBlockContaining(hash);

  final BigInteger expectedEndBalance = startBalance.add(transferAmountWei);
  final BigInteger actualEndBalance = ethNode.accounts().balance(RECIPIENT);
  assertThat(actualEndBalance).isEqualTo(expectedEndBalance);
}
 
Example #9
Source File: ReadTimeoutAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void submittingTransactionReturnsAGatewayTimeoutError() {
  final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00";
  final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact();

  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          richBenefactor().nextNonceAndIncrement(),
          GAS_PRICE,
          INTRINSIC_GAS,
          recipient,
          transferAmountWei);
  final SignerResponse<JsonRpcErrorResponse> signerResponse =
      ethSigner.transactions().submitExceptional(transaction);
  assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT);
  assertThat(signerResponse.jsonRpc().getError())
      .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT);
}
 
Example #10
Source File: ConnectionTimeoutAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void submittingTransactionReturnsAGatewayTimeoutError() {
  final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00";
  final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact();

  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          richBenefactor().nextNonceAndIncrement(),
          GAS_PRICE,
          INTRINSIC_GAS,
          recipient,
          transferAmountWei);
  final SignerResponse<JsonRpcErrorResponse> signerResponse =
      ethSigner.transactions().submitExceptional(transaction);
  assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT);
  assertThat(signerResponse.jsonRpc().getError())
      .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT);
}
 
Example #11
Source File: ConnectionTimeoutAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void submittingTransactionWithoutNonceReturnsAGatewayTimeoutError() {
  final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00";
  final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact();

  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          recipient,
          transferAmountWei);
  final SignerResponse<JsonRpcErrorResponse> signerResponse =
      ethSigner.transactions().submitExceptional(transaction);
  assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT);
  assertThat(signerResponse.jsonRpc().getError())
      .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT);
}
 
Example #12
Source File: DataPathFeatureFlagAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
public void valueTransfer() {
  final BigInteger transferAmountWei = Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact();
  final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT);
  final Transaction transaction =
      Transaction.createEtherTransaction(
          richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          RECIPIENT,
          transferAmountWei);

  final String hash = ethSigner().transactions().submit(transaction);
  ethNode().transactions().awaitBlockContaining(hash);

  final BigInteger expectedEndBalance = startBalance.add(transferAmountWei);
  final BigInteger actualEndBalance = ethNode().accounts().balance(RECIPIENT);
  assertThat(actualEndBalance).isEqualTo(expectedEndBalance);
}
 
Example #13
Source File: ClientSideTlsAcceptanceTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void ethSignerDoesNotConnectToServerNotSpecifiedInTrustStore(@TempDir Path workDir)
    throws Exception {
  final TlsCertificateDefinition serverPresentedCert =
      TlsCertificateDefinition.loadFromResource("tls/cert1.pfx", "password");
  final TlsCertificateDefinition ethSignerCert =
      TlsCertificateDefinition.loadFromResource("tls/cert2.pfx", "password2");
  final TlsCertificateDefinition ethSignerExpectedServerCert =
      TlsCertificateDefinition.loadFromResource("tls/cert2.pfx", "password2");

  final HttpServer web3ProviderHttpServer =
      serverFactory.create(serverPresentedCert, ethSignerCert, workDir);

  signer =
      createAndStartSigner(
          ethSignerCert,
          ethSignerExpectedServerCert,
          web3ProviderHttpServer.actualPort(),
          0,
          workDir);

  assertThatThrownBy(() -> signer.accounts().balance("0x123456"))
      .isInstanceOf(ClientConnectionException.class)
      .hasMessageContaining(String.valueOf(BAD_GATEWAY.code()));

  // ensure submitting a transaction results in the same behaviour
  final Transaction transaction =
      Transaction.createEtherTransaction(
          signer.accounts().richBenefactor().address(),
          null,
          GAS_PRICE,
          INTRINSIC_GAS,
          "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00",
          Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact());

  assertThatThrownBy(() -> signer.transactions().submit(transaction))
      .isInstanceOf(ClientConnectionException.class)
      .hasMessageContaining(String.valueOf(BAD_GATEWAY.code()));
}
 
Example #14
Source File: ExpectAccountBalance.java    From besu with Apache License 2.0 5 votes vote down vote up
public ExpectAccountBalance(
    final EthTransactions eth,
    final Account account,
    final BigDecimal expectedBalance,
    final Unit balanceUnit) {
  this.account = account;
  this.eth = eth;
  this.expectedBalance = toWei(expectedBalance, balanceUnit).toBigIntegerExact();
}
 
Example #15
Source File: ExpectAccountBalanceAtBlock.java    From besu with Apache License 2.0 5 votes vote down vote up
public ExpectAccountBalanceAtBlock(
    final EthTransactions eth,
    final Account account,
    final BigInteger block,
    final BigDecimal expectedBalance,
    final Unit balanceUnit) {
  this.account = account;
  this.eth = eth;
  this.block = block;
  this.expectedBalance = toWei(expectedBalance, balanceUnit).toBigIntegerExact();
}
 
Example #16
Source File: ExpectAccountBalanceNotChanging.java    From besu with Apache License 2.0 5 votes vote down vote up
public ExpectAccountBalanceNotChanging(
    final EthTransactions eth,
    final Account account,
    final BigDecimal startBalance,
    final Unit balanceUnit) {
  this.account = account;
  this.eth = eth;
  this.startBalance = toWei(startBalance, balanceUnit).toBigIntegerExact();
}
 
Example #17
Source File: StakingContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void addStaking() {
    try {
    	StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
        BigDecimal addStakingAmount = Convert.toVon("4000000", Unit.LAT).add(new BigDecimal("999999999999999998"));
    	
        PlatonSendTransaction platonSendTransaction = stakingContract.addStakingReturnTransaction(nodeId, stakingAmountType, addStakingAmount.toBigInteger()).send();
        TransactionResponse baseResponse = stakingContract.getTransactionResponse(platonSendTransaction).send();
        System.out.println(baseResponse.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #18
Source File: StakingContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void staking() throws Exception {   	
    try {
    	StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    	String benifitAddress = benefitCredentials.getAddress();
    	String externalId = "";
        String nodeName = "chendai-node3";
        String webSite = "www.baidu.com";
        String details = "chendai-node3-details";
        BigDecimal stakingAmount = Convert.toVon("5000000", Unit.LAT);
        BigInteger rewardPer = BigInteger.valueOf(1000L);
    	
        PlatonSendTransaction platonSendTransaction = stakingContract.stakingReturnTransaction(new StakingParam.Builder()
                .setNodeId(nodeId)
                .setAmount(stakingAmount.toBigInteger())  
                .setStakingAmountType(stakingAmountType)
                .setBenifitAddress(benifitAddress)
                .setExternalId(externalId)
                .setNodeName(nodeName)
                .setWebSite(webSite)
                .setDetails(details)
                .setBlsPubKey(blsPubKey)
                .setProcessVersion(web3j.getProgramVersion().send().getAdminProgramVersion())
                .setBlsProof(web3j.getSchnorrNIZKProve().send().getAdminSchnorrNIZKProve())
                .setRewardPer(rewardPer)
                .build()).send();
        TransactionResponse baseResponse = stakingContract.getTransactionResponse(platonSendTransaction).send();
        System.out.println(baseResponse.toString());  //394
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public TransactionResponse delegate() throws Exception {
    StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    BigDecimal stakingAmount = Convert.toVon("500000", Unit.LAT);

    PlatonSendTransaction platonSendTransaction = delegateContract.delegateReturnTransaction(nodeId, stakingAmountType, stakingAmount.toBigInteger()).send();
    TransactionResponse baseResponse = delegateContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}
 
Example #20
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public TransactionResponse addStaking() throws Exception {
    StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    BigDecimal addStakingAmount = Convert.toVon("4000000", Unit.LAT).add(new BigDecimal("999999999999999998"));

    PlatonSendTransaction platonSendTransaction = stakingContract.addStakingReturnTransaction(nodeId, stakingAmountType, addStakingAmount.toBigInteger()).send();
    TransactionResponse baseResponse = stakingContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}
 
Example #21
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public TransactionResponse staking() throws Exception {
    StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    String benifitAddress = benefitCredentials.getAddress();
    String externalId = "";
    String nodeName = "integration-node1";
    String webSite = "https://www.platon.network/#/";
    String details = "integration-node1-details";
    BigDecimal stakingAmount = Convert.toVon("5000000", Unit.LAT).add(BigDecimal.valueOf(1L));
    BigInteger rewardPer = BigInteger.valueOf(1000L);

    PlatonSendTransaction platonSendTransaction = stakingContract.stakingReturnTransaction(new StakingParam.Builder()
            .setNodeId(nodeId)
            .setAmount(stakingAmount.toBigInteger())
            .setStakingAmountType(stakingAmountType)
            .setBenifitAddress(benifitAddress)
            .setExternalId(externalId)
            .setNodeName(nodeName)
            .setWebSite(webSite)
            .setDetails(details)
            .setBlsPubKey(blsPubKey)
            .setProcessVersion(web3j.getProgramVersion().send().getAdminProgramVersion())
            .setBlsProof(web3j.getSchnorrNIZKProve().send().getAdminSchnorrNIZKProve())
            .setRewardPer(rewardPer)
            .build()).send();
    TransactionResponse baseResponse = stakingContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}
 
Example #22
Source File: RewardContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, deleteCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
    System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(deleteCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #23
Source File: ProposalContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), new BigDecimal("10000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(stakingCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #24
Source File: EthereumWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    try {
        when(web3j.ethGetBalance(anyString(),
                                 any(DefaultBlockParameterName.class))).thenReturn(balanceRequest);
        when(balanceRequest.send()).thenReturn(ethGetBalance);
        when(ethGetBalance.getBalance()).thenReturn(BigInteger.valueOf(100));
        when(transfer.sendFunds(anyString(),
                                any(BigDecimal.class),
                                any(Unit.class))).thenReturn(transferRequest);
        when(transferRequest.send()).thenReturn(transactionReceipt);
        when(transactionReceipt.getStatus()).thenReturn("testStatus");
        when(transactionReceipt.getBlockHash()).thenReturn("testBlockHash");
        when(transactionReceipt.getBlockNumber()).thenReturn(BigInteger.valueOf(1));
        when(web3j.ethCall(any(Transaction.class),
                           any(DefaultBlockParameterName.class))).thenReturn(ethCallRequest);
        when(ethCallRequest.sendAsync()).thenReturn(ethCallCompletable);
        when(ethCallCompletable.get()).thenReturn(ethCall);
        when(ethCall.getValue()).thenReturn("testResultValue");
        when(web3j.ethGetTransactionCount(anyString(),
                                          any(DefaultBlockParameterName.class))).thenReturn(ethCountRequest);
        when(ethCountRequest.sendAsync()).thenReturn(ethCountCompletable);
        when(ethCountCompletable.get()).thenReturn(transactionCount);
        when(transactionCount.getTransactionCount()).thenReturn(BigInteger.valueOf(10));
        when(web3j.ethSendTransaction(any(Transaction.class))).thenReturn(ethSendRequest);
        when(ethSendRequest.sendAsync()).thenReturn(ethSendCompletable);
        when(ethSendCompletable.get()).thenReturn(ethSendTransaction);
        when(ethSendTransaction.getTransactionHash()).thenReturn("testTransactionHash");
        when(web3j.ethSendRawTransaction(anyString())).thenReturn(ethSendRawRequest);
        when(ethSendRawRequest.sendAsync()).thenReturn(ethSendRawCompletable);
        when(ethSendRawCompletable.get()).thenReturn(ethSendRawTransaction);
        when(ethSendRawTransaction.getTransactionHash()).thenReturn("testTransactionHash");
        when(web3j.ethGetTransactionReceipt(anyString())).thenReturn(ethSendTransactionReceipt);
        when(ethSendTransactionReceipt.send()).thenReturn(ethGetTransactionReceipt);
        when(ethGetTransactionReceipt.getTransactionReceipt()).thenReturn(Optional.of(rawTransactionalRecept));
        when(ethGetTransactionReceipt.getResult()).thenReturn(rawTransactionalRecept);
        when(rawTransactionalRecept.getContractAddress()).thenReturn("testContractAddress");

        signalList = new ArrayList();
        doAnswer(new Answer() {
            public Void answer(InvocationOnMock invocation) {
                signalList.add(Arrays.toString(invocation.getArguments()));
                return null;
            }
        }).when(kieSession).signalEvent(anyString(),
                                        any(Object.class));

        Observable logObservable = PowerMockito.mock(Observable.class);
        when(web3j.ethLogObservable(any(EthFilter.class))).thenReturn(logObservable);
        when(logObservable.subscribe()).thenReturn(subscription);
        when(logObservable.subscribe(any(Action1.class))).thenReturn(subscription);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
 
Example #25
Source File: StakingContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(stakingCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #26
Source File: DelegateContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, deleteCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(deleteCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #27
Source File: ProposalScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, proposalCredentials.getAddress(), transferValue, Unit.LAT).send();
    Transfer.sendFunds(web3j, superCredentials, chainId, voteCredentials.getAddress(), transferValue, Unit.LAT).send();
}
 
Example #28
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), transferValue, Unit.LAT).send();
    Transfer.sendFunds(web3j, superCredentials, chainId, delegateCredentials.getAddress(), transferValue, Unit.LAT).send();
}
 
Example #29
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public TransactionResponse unDelegate(BigInteger stakingBlockNum) throws Exception {
    BigDecimal stakingAmount = Convert.toVon("500000", Unit.LAT);
    PlatonSendTransaction platonSendTransaction = delegateContract.unDelegateReturnTransaction(nodeId, stakingBlockNum, stakingAmount.toBigInteger()).send();
    TransactionResponse baseResponse = delegateContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}
 
Example #30
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
/**
 * 正常的场景:
 * 初始化账户余额
 * 创建质押信息(1000)
 * 修改质押信息(1001)
 * 修改质押金额(1002)
 * 对质押委托(1004)
 * 查询当前结算周期的验证人队列(1100)
 * 查询当前共识周期的验证人列表(1101)
 * 查询所有实时的候选人列表(1102)
 * 查询当前账户地址所委托的节点的NodeID和质押Id(1103)
 * 查询当前单个委托信息(1104)
 * 查询当前节点的质押信息(1105)
 * 对质押解除委托(1005)
 * 退出质押(1003)
 */
@Test
public void executeScenario() throws Exception {
    //初始化账户余额
    transfer();
    BigInteger stakingBalance = web3j.platonGetBalance(stakingCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance();
    BigInteger delegateBalance = web3j.platonGetBalance(delegateCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance();

    assertTrue(new BigDecimal(stakingBalance).compareTo(Convert.fromVon(transferValue, Unit.VON)) >= 0);
    assertTrue(new BigDecimal(delegateBalance).compareTo(Convert.fromVon(transferValue, Unit.VON)) >= 0);

    //创建质押信息(1000)
    TransactionResponse createStakingResponse = staking();
    assertTrue(createStakingResponse.toString(), createStakingResponse.isStatusOk());

    //修改质押信息(1001)
    TransactionResponse updateStakingResponse = updateStakingInfo();
    assertTrue(updateStakingResponse.toString(), updateStakingResponse.isStatusOk());

    //修改质押金额(1002)
    TransactionResponse addStakingResponse = addStaking();
    assertTrue(addStakingResponse.toString(), addStakingResponse.isStatusOk());

    //对质押委托(1004)
    TransactionResponse delegateResponse = delegate();
    assertTrue(delegateResponse.toString(), delegateResponse.isStatusOk());

    //查询当前账户地址所委托的节点的NodeID和质押Id(1103)
    CallResponse<List<DelegationIdInfo>> getRelatedListByDelAddrResponse = getRelatedListByDelAddr();
    assertTrue(getRelatedListByDelAddrResponse.toString(), getRelatedListByDelAddrResponse.isStatusOk());

    List<DelegationIdInfo> delegationIdInfos = getRelatedListByDelAddrResponse.getData();
    assertTrue(delegationIdInfos != null && !delegationIdInfos.isEmpty());

    //查询当前单个委托信息(1104)
    CallResponse<Delegation> getDelegateResponse = getDelegateInfo(delegationIdInfos.get(0).getStakingBlockNum());
    assertTrue(getDelegateResponse.toString(), getDelegateResponse.isStatusOk());

    //查询当前节点的质押信息(1105)
    CallResponse<Node> getStakingInfoResponse = getStakingInfo();
    assertTrue(getStakingInfoResponse.toString(), getStakingInfoResponse.isStatusOk());

    //对质押解除委托(1005)
    TransactionResponse unDelegateResponse = unDelegate(delegationIdInfos.get(0).getStakingBlockNum());
    assertTrue(unDelegateResponse.toString(), unDelegateResponse.isStatusOk());

    //退出质押(1003)
    TransactionResponse unStakingResponse = unStaking();
    assertTrue(unStakingResponse.toString(), unStakingResponse.isStatusOk());
}