-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ElBridgeClient, moving classes
- Loading branch information
1 parent
dfc14fe
commit 2e6bb88
Showing
12 changed files
with
151 additions
and
15 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
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
15 changes: 15 additions & 0 deletions
15
consensus-client-it/src/test/scala/units/BridgeTestSuite.scala
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,15 @@ | ||
package units | ||
|
||
class BridgeTestSuite extends BaseItTestSuite { | ||
"L2-379 Checking balances in EL->CL transfers" in { | ||
val sendResult = ec1.elBridge.sendNative(elRichAccount1, clRichAccount1.toAddress, BigInt("1000000000000000000")) | ||
Thread.sleep(60000) | ||
|
||
// waves1.api.broadcastAndWait( | ||
// chainContract.withdraw( | ||
// ) | ||
// ) | ||
} | ||
|
||
"L2-380 Checking balances in CL->EL transfers" in {} | ||
} |
2 changes: 1 addition & 1 deletion
2
...scala/units/network/RewardTestSuite.scala → ...rc/test/scala/units/RewardTestSuite.scala
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
2 changes: 1 addition & 1 deletion
2
...s/network/test/docker/BaseContainer.scala → ...st/scala/units/docker/BaseContainer.scala
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
2 changes: 1 addition & 1 deletion
2
...etwork/test/docker/GenericContainer.scala → ...scala/units/docker/GenericContainer.scala
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
2 changes: 1 addition & 1 deletion
2
.../units/network/test/docker/Networks.scala → ...rc/test/scala/units/docker/Networks.scala
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
56 changes: 56 additions & 0 deletions
56
consensus-client-it/src/test/scala/units/el/ElBridgeClient.scala
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,56 @@ | ||
package units.el | ||
|
||
import com.wavesplatform.account.Address | ||
import com.wavesplatform.utils.{EthEncoding, ScorexLogging} | ||
import org.web3j.abi.datatypes.generated.Bytes20 | ||
import org.web3j.abi.datatypes.{Type, Function as Web3Function} | ||
import org.web3j.crypto.{Credentials, RawTransaction, TransactionEncoder} | ||
import org.web3j.protocol.Web3j | ||
import org.web3j.protocol.core.DefaultBlockParameterName | ||
import org.web3j.protocol.core.methods.response.EthSendTransaction | ||
import org.web3j.tx.gas.DefaultGasProvider | ||
import org.web3j.utils.Numeric | ||
import units.eth.EthAddress | ||
|
||
import java.util.concurrent.ThreadLocalRandom | ||
import scala.jdk.CollectionConverters.SeqHasAsJava | ||
|
||
class ElBridgeClient(web3j: Web3j, val address: EthAddress) extends ScorexLogging { | ||
def sendNative(sender: Credentials, recipient: Address, amountInEther: BigInt): EthSendTransaction = { | ||
val currRequestId = ThreadLocalRandom.current().nextInt(10000, 100000).toString | ||
|
||
val senderAddress = sender.getAddress | ||
log.debug(s"[$currRequestId] sendNative($senderAddress->$recipient: $amountInEther Ether)") | ||
|
||
val recipientAddressHex = Numeric.toHexString(recipient.publicKeyHash) | ||
val data = org.web3j.abi.FunctionEncoder.encode( | ||
new Web3Function( | ||
"sendNative", | ||
List[Type[?]](new Bytes20(EthEncoding.toBytes(recipientAddressHex))).asJava, | ||
List.empty.asJava | ||
) | ||
) | ||
|
||
val ethGetTransactionCount = web3j | ||
.ethGetTransactionCount(senderAddress, DefaultBlockParameterName.LATEST) | ||
.send() | ||
val nonce = ethGetTransactionCount.getTransactionCount | ||
|
||
val transaction = RawTransaction.createTransaction( | ||
nonce, | ||
DefaultGasProvider.GAS_PRICE, | ||
DefaultGasProvider.GAS_LIMIT, | ||
address.hex, | ||
amountInEther.bigInteger, | ||
data | ||
) | ||
|
||
val signedMessage = TransactionEncoder.signMessage(transaction, sender) | ||
val hexValue = Numeric.toHexString(signedMessage) | ||
val r = web3j.ethSendRawTransaction(hexValue).send() | ||
|
||
log.debug(s"[$currRequestId] txn=${r.getTransactionHash}") | ||
r | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
consensus-client-it/src/test/scala/units/http/OkHttpLogger.scala
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,37 @@ | ||
package units.http | ||
|
||
import com.wavesplatform.utils.ScorexLogging | ||
import okhttp3.{Interceptor, Request, Response} | ||
|
||
import java.util.concurrent.ThreadLocalRandom | ||
import scala.util.Try | ||
|
||
object OkHttpLogger extends Interceptor with ScorexLogging { | ||
override def intercept(chain: Interceptor.Chain): Response = { | ||
val currRequestId = ThreadLocalRandom.current().nextInt(10000, 100000).toString | ||
val req = chain.request() | ||
log.debug(s"[$currRequestId] ${req.url()} ${readRequestBody(req)}") | ||
val res = chain.proceed(req) | ||
log.debug(s"[$currRequestId] ${res.code()}: ${readResponseBody(res)}") | ||
res | ||
} | ||
|
||
private def readRequestBody(request: Request) = request.body() match { | ||
case null => "null" | ||
case body => | ||
val buffer = new okio.Buffer() | ||
Try { | ||
body.writeTo(buffer) | ||
buffer.readUtf8() | ||
}.getOrElse("Could not read body") | ||
} | ||
|
||
private def readResponseBody(response: Response) = response.body() match { | ||
case null => "null" | ||
case body => | ||
val source = body.source() | ||
source.request(Long.MaxValue) // Buffer the entire body. | ||
val buffer = source.buffer().clone() | ||
buffer.readUtf8() | ||
} | ||
} |