This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance test - configurable gas price (#1023)
- Loading branch information
Showing
6 changed files
with
243 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...nce-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/blockchain/Amount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.blockchain; | ||
|
||
import static org.web3j.utils.Convert.Unit.ETHER; | ||
import static org.web3j.utils.Convert.Unit.WEI; | ||
|
||
import java.math.BigInteger; | ||
|
||
import org.web3j.utils.Convert; | ||
import org.web3j.utils.Convert.Unit; | ||
|
||
public class Amount { | ||
|
||
private String value; | ||
private Unit unit; | ||
|
||
private Amount(final long value, final Unit unit) { | ||
this.value = String.valueOf(value); | ||
this.unit = unit; | ||
} | ||
|
||
private Amount(final BigInteger value, final Unit unit) { | ||
this.value = value.toString(); | ||
this.unit = unit; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public Unit getUnit() { | ||
return unit; | ||
} | ||
|
||
public Amount subtract(final Amount subtracting) { | ||
|
||
final Unit denominator; | ||
if (unit.getWeiFactor().compareTo(subtracting.unit.getWeiFactor()) == -1) { | ||
denominator = unit; | ||
} else { | ||
denominator = subtracting.unit; | ||
} | ||
|
||
final BigInteger result = | ||
Convert.fromWei( | ||
Convert.toWei(value, unit) | ||
.subtract(Convert.toWei(subtracting.value, subtracting.unit)), | ||
denominator) | ||
.toBigInteger(); | ||
|
||
return new Amount(result, denominator); | ||
} | ||
|
||
public static Amount ether(final long value) { | ||
return new Amount(value, ETHER); | ||
} | ||
|
||
public static Amount wei(final BigInteger value) { | ||
return new Amount(value, WEI); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...pegasys/pantheon/tests/acceptance/dsl/transaction/account/TransferTransactionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.account; | ||
|
||
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.blockchain.Amount; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class TransferTransactionBuilder { | ||
|
||
private Account sender; | ||
private Account recipient; | ||
private Amount transferAmount; | ||
private Amount gasPrice; | ||
private BigInteger nonce; | ||
|
||
public TransferTransactionBuilder sender(final Account sender) { | ||
this.sender = sender; | ||
validateSender(); | ||
return this; | ||
} | ||
|
||
public TransferTransactionBuilder recipient(final Account recipient) { | ||
this.recipient = recipient; | ||
return this; | ||
} | ||
|
||
public TransferTransactionBuilder amount(final Amount transferAmount) { | ||
this.transferAmount = transferAmount; | ||
validateTransferAmount(); | ||
return this; | ||
} | ||
|
||
public TransferTransactionBuilder nonce(final BigInteger nonce) { | ||
this.nonce = nonce; | ||
return this; | ||
} | ||
|
||
public TransferTransactionBuilder gasPrice(final Amount gasPrice) { | ||
this.gasPrice = gasPrice; | ||
return this; | ||
} | ||
|
||
public TransferTransaction build() { | ||
validateSender(); | ||
validateTransferAmount(); | ||
return new TransferTransaction(sender, recipient, transferAmount, gasPrice, nonce); | ||
} | ||
|
||
private void validateSender() { | ||
if (sender == null) { | ||
throw new IllegalArgumentException("NULL sender is not allowed."); | ||
} | ||
} | ||
|
||
private void validateTransferAmount() { | ||
if (transferAmount == null) { | ||
throw new IllegalArgumentException("NULL transferAmount is not allowed."); | ||
} | ||
} | ||
} |