Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to sepolia #97

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import org.web3j.contracts.eip20.generated.ERC20
import org.web3j.contracts.eip721.generated.ERC721
import org.web3j.crypto.*
import org.web3j.crypto.Credentials
import org.web3j.crypto.Sign
import org.web3j.crypto.StructuredDataEncoder
import org.web3j.protocol.Web3j
import org.web3j.protocol.Web3jService
import org.web3j.protocol.core.methods.response.EthBlock
Expand Down Expand Up @@ -717,7 +719,9 @@ class DefaultEthereumInteraction(

companion object {

@Deprecated("Use REDDIO_DEPLOY_HELPER_ADDRESS_SEPOLIA")
const val REDDIO_DEPLOY_HELPER_ADDRESS_GOERLI = "0xE6f26945d915A9C6d5ebaF26a0dcD99caE74347d"
const val REDDIO_DEPLOY_HELPER_ADDRESS_SEPOLIA = "0xE6f26945d915A9C6d5ebaF26a0dcD99caE74347d"

private const val SIGN_MESSAGE = "Generate layer 2 key"
private val objectMapper = ObjectMapper()
Expand Down Expand Up @@ -780,7 +784,10 @@ class DefaultEthereumInteraction(


const val MAINNET_ID = 1L;

@Deprecated("Use SEPOLIA_ID")
const val GOERIL_ID = 5L;
const val SEPOLIA_ID = 11155111L;

@JvmStatic
fun build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import com.reddio.IntegrationTest;
import com.reddio.abi.Erc721m;
import com.reddio.api.v1.rest.DefaultReddioRestClient;
import com.reddio.api.v1.rest.GetContractInfoMessage;
import com.reddio.api.v1.rest.GetContractInfoResponse;
import com.reddio.api.v1.rest.ResponseWrapper;
import com.reddio.crypto.CryptoService;
import com.reddio.gas.GasOption;
import com.reddio.gas.StaticGasLimitSuggestionPriceGasProvider;
import io.reactivex.disposables.Disposable;
Expand All @@ -19,15 +15,11 @@
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;

import java.io.IOException;
import java.lang.ref.Reference;
import java.math.BigInteger;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;

public class DefaultEthereumInteractionTest {
Expand All @@ -42,9 +34,9 @@ public class DefaultEthereumInteractionTest {
public void testWatchDeposit() throws InterruptedException, IOException {
ObjectMapper om = new ObjectMapper();
DefaultReddioRestClient restClient = DefaultReddioRestClient.testnet();
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.GOERIL_ID, "https://eth-goerli.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT", "0x0");
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.SEPOLIA_ID, "https://eth-sepolia.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT", "0x0");
Long requiredBlockConfirmations = 2L;
Web3j web3j = Web3j.build(new HttpService("https://eth-goerli.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT"));
Web3j web3j = Web3j.build(new HttpService("https://eth-sepolia.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT"));
BigInteger startBlockNumber = web3j.ethBlockNumber().send().getBlockNumber();

AtomicReference<Disposable> disposableReference = new AtomicReference<>();
Expand Down Expand Up @@ -77,7 +69,7 @@ public void testWatchDeposit() throws InterruptedException, IOException {
public void testWatchNftDeposit() throws InterruptedException {
ObjectMapper om = new ObjectMapper();
DefaultReddioRestClient restClient = DefaultReddioRestClient.testnet();
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.GOERIL_ID, "https://eth-goerli.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT", "0x0");
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.SEPOLIA_ID, "https://eth-sepolia.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT", "0x0");
Disposable disposable = ethereumInteraction.watchNftDeposit((it) -> {
try {
String asJson = om.writeValueAsString(it);
Expand All @@ -93,30 +85,30 @@ public void testWatchNftDeposit() throws InterruptedException {
@Test
public void testEthSignAndGetStarkKey() {
DefaultReddioRestClient restClient = DefaultReddioRestClient.testnet();
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.GOERIL_ID, "https://eth-goerli.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT",
DefaultEthereumInteraction ethereumInteraction = DefaultEthereumInteraction.build(restClient, DefaultEthereumInteraction.SEPOLIA_ID, "https://eth-sepolia.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT",
"552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b");
BigInteger result = ethereumInteraction.getStarkPrivateKey();
Assert.assertEquals("5f6fbfbcd995e20f94a768193c42060f7e626e6ae8042cacc15e82031087a55", result.toString(16));
Assert.assertEquals("56035b2159b8240c17267a541713b18f697d54eb6da0eed8dfcb33144a05100", result.toString(16));
}

@Test
public void testEthSignAndGetStarkKeyStaticMethod() {
BigInteger result = DefaultEthereumInteraction.getStarkPrivateKey("552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b", DefaultEthereumInteraction.GOERIL_ID);
Assert.assertEquals("5f6fbfbcd995e20f94a768193c42060f7e626e6ae8042cacc15e82031087a55", result.toString(16));
BigInteger result = DefaultEthereumInteraction.getStarkPrivateKey("552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b", DefaultEthereumInteraction.SEPOLIA_ID);
Assert.assertEquals("56035b2159b8240c17267a541713b18f697d54eb6da0eed8dfcb33144a05100", result.toString(16));
}

@Test
public void testGetStarkKeys() {
StarkKeys starkKeys = DefaultEthereumInteraction.getStarkKeys("552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b", DefaultEthereumInteraction.GOERIL_ID);
Assert.assertEquals("0x13a69a1b7a5f033ee2358ebb8c28fd5a6b86d42e30a61845d655d3c7be4ad0e", starkKeys.getStarkKey());
Assert.assertEquals("0x5f6fbfbcd995e20f94a768193c42060f7e626e6ae8042cacc15e82031087a55", starkKeys.getStarkPrivateKey());
StarkKeys starkKeys = DefaultEthereumInteraction.getStarkKeys("552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b", DefaultEthereumInteraction.SEPOLIA_ID);
Assert.assertEquals("0x79bec1efb30903621fc11d81b9b1a4af25d0eb1555332ec72487d2ed3692174", starkKeys.getStarkKey());
Assert.assertEquals("0x56035b2159b8240c17267a541713b18f697d54eb6da0eed8dfcb33144a05100", starkKeys.getStarkPrivateKey());
}

@Test
@Category(IntegrationTest.class)
@Ignore("Insufficient funds for gas")
public void testDeployERC721M() throws Exception {
Web3j web3j = Web3j.build(new HttpService("https://eth-goerli.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT"));
Web3j web3j = Web3j.build(new HttpService("https://eth-sepolia.g.alchemy.com/v2/yyabgQ1GlM0xxqDC4ZBbR1lBcBKQmnxT"));
Credentials credentials = Credentials.create("552ad9b756acfeb2e32cfd3354b653b1f95177b851a44155d6178d244b80e08b");
StaticGasLimitSuggestionPriceGasProvider gasProvider = new StaticGasLimitSuggestionPriceGasProvider(5, GasOption.Market, new BigInteger("10000000"));
RemoteCall<Erc721m> deployRemoteCall = Erc721m.deploy(web3j, credentials, gasProvider, "NON3", "NON3", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import com.reddio.api.v1.rest.OrderState;
import com.reddio.api.v1.rest.ReddioRestClient;
import com.reddio.exception.ReddioException;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.concurrent.CompletionException;

import static org.junit.Assert.*;


@Ignore
public class OrderPollerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import com.reddio.api.v1.rest.ReddioRestClient;
import com.reddio.api.v1.rest.SequenceRecord;
import com.reddio.exception.ReddioException;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.concurrent.CompletionException;

import static org.junit.Assert.*;

@Ignore
public class RecordPollerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.reddio.api.v1.rest.DefaultReddioRestClient
import com.reddio.fixtures.Fixtures
import com.reddio.gas.GasOption
import mu.KotlinLogging
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category


private val logger = KotlinLogging.logger {}

@Category(IntegrationTest::class)
@Ignore
class DefaultEthereumInteractionDepositIntegrationTest {

@Test
Expand All @@ -20,7 +22,7 @@ class DefaultEthereumInteractionDepositIntegrationTest {
val (toDeposit, ethOwnership) = Fixtures.fetchStarkKeysWhichOwnETHOnLayer1(depositAmount)
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
toDeposit.ethPrivateKey
)
Expand All @@ -36,7 +38,7 @@ class DefaultEthereumInteractionDepositIntegrationTest {
val (toDeposit, erC20Ownership) = Fixtures.fetchStarkKeysWhichOwnERC20OnLayer1(balance = depositAmount)
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
toDeposit.ethPrivateKey
)
Expand All @@ -51,7 +53,7 @@ class DefaultEthereumInteractionDepositIntegrationTest {
val (toDeposit, erC721Ownership) = Fixtures.fetchStarkKeysWhichOwnERC721OnLayer1()
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
toDeposit.ethPrivateKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import com.reddio.gas.GasOption
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import mu.KotlinLogging

import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import java.util.concurrent.locks.ReentrantLock


private val logger = KotlinLogging.logger {}

@RunWith(Enclosed::class)
@Category(IntegrationTest::class)
@Ignore
class DefaultEthereumInteractionWatchDepositEventIntegrationTest {

@Category(IntegrationTest::class)
Expand All @@ -30,7 +30,7 @@ class DefaultEthereumInteractionWatchDepositEventIntegrationTest {
val (toDeposit, erC20Ownership) = Fixtures.fetchStarkKeysWhichOwnERC20OnLayer1(balance = depositAmount)
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
toDeposit.ethPrivateKey
)
Expand All @@ -45,7 +45,7 @@ class DefaultEthereumInteractionWatchDepositEventIntegrationTest {
fun testWatchDeposit() {
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
"0x0"
)
Expand All @@ -71,7 +71,7 @@ class DefaultEthereumInteractionWatchDepositEventIntegrationTest {
val (toDeposit, erC721Ownership) = Fixtures.fetchStarkKeysWhichOwnERC721OnLayer1()
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
toDeposit.ethPrivateKey
)
Expand All @@ -86,7 +86,7 @@ class DefaultEthereumInteractionWatchDepositEventIntegrationTest {
fun testWatchNftDeposit() {
val ethereumInteraction = DefaultEthereumInteraction.build(
DefaultReddioRestClient.testnet(),
DefaultEthereumInteraction.GOERIL_ID,
DefaultEthereumInteraction.SEPOLIA_ID,
Fixtures.fetchETHJsonRPCNode(),
"0x0"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import com.reddio.fixtures.Fixtures
import com.reddio.gas.GasOption
import mu.KotlinLogging
import org.junit.Assume
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category


private val logger = KotlinLogging.logger {}

@Category(IntegrationTest::class)
@Ignore
class DefaultEthereumInteractionWithdrawalIntegrationTest {
@Test
fun testWithdrawETH() {
try {
val (account, record) = Fixtures.fetchStarkKeysWhichCouldWithdrawalETHOnLayer1()
val restClient = DefaultReddioRestClient.testnet()
val ethereumInteraction = DefaultEthereumInteraction.build(
restClient, DefaultEthereumInteraction.GOERIL_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
restClient, DefaultEthereumInteraction.SEPOLIA_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
)

val log = ethereumInteraction.withdrawalETH(
Expand All @@ -41,7 +43,7 @@ class DefaultEthereumInteractionWithdrawalIntegrationTest {
val (account, record) = Fixtures.fetchStarkKeysWhichCouldWithdrawalERC20OnLayer1()
val restClient = DefaultReddioRestClient.testnet()
val ethereumInteraction = DefaultEthereumInteraction.build(
restClient, DefaultEthereumInteraction.GOERIL_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
restClient, DefaultEthereumInteraction.SEPOLIA_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
)
val log = ethereumInteraction.withdrawalERC20(
account.ethAddress, record.contractAddress, GasOption.Market
Expand All @@ -60,7 +62,7 @@ class DefaultEthereumInteractionWithdrawalIntegrationTest {
val (account, record) = Fixtures.fetchStarkKeysWhichCouldWithdrawalERC721OnLayer1()
val restClient = DefaultReddioRestClient.testnet()
val ethereumInteraction = DefaultEthereumInteraction.build(
restClient, DefaultEthereumInteraction.GOERIL_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
restClient, DefaultEthereumInteraction.SEPOLIA_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
)

val log = ethereumInteraction.withdrawalERC721(
Expand All @@ -80,7 +82,7 @@ class DefaultEthereumInteractionWithdrawalIntegrationTest {
val (account, record) = Fixtures.fetchStarkKeysWhichCouldWithdrawalERC721MOnLayer1()
val restClient = DefaultReddioRestClient.testnet()
val ethereumInteraction = DefaultEthereumInteraction.build(
restClient, DefaultEthereumInteraction.GOERIL_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
restClient, DefaultEthereumInteraction.SEPOLIA_ID, Fixtures.fetchETHJsonRPCNode(), account.ethPrivateKey
)

val log = ethereumInteraction.withdrawalERC721M(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.reddio.IntegrationTest
import com.reddio.api.v1.requests.ReddioWithdrawalToApi.Companion.withdrawalERC721
import com.reddio.api.v1.rest.*
import com.reddio.api.v1.rest.DefaultReddioRestClient
import com.reddio.crypto.CryptoService
import com.reddio.exception.ReddioBusinessException
import com.reddio.exception.ReddioErrorCode
Expand All @@ -20,6 +20,7 @@ import java.util.concurrent.ExecutionException
private val logger = KotlinLogging.logger {}

@Category(IntegrationTest::class)
@Ignore
class DefaultReddioClientIntegrationTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.reddio.api.v1

import com.reddio.IntegrationTest
import com.reddio.fixtures.FixtureException
import com.reddio.fixtures.Fixtures
import com.reddio.fixtures.StarkKeysPool
import mu.KotlinLogging
import org.junit.Assert
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category

private val logger = KotlinLogging.logger {}


@Ignore
@Category(IntegrationTest::class)
class DefaultReddioClientMintIntegrationTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import com.reddio.fixtures.Fixtures
import com.reddio.fixtures.StarkKeysPool
import mu.KotlinLogging
import org.junit.Assert
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category
import java.time.Instant


private val logger = KotlinLogging.logger {}

@Ignore
@Category(IntegrationTest::class)
class DefaultReddioClientOrderIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package com.reddio.api.v1

import com.reddio.IntegrationTest
import com.reddio.api.v1.rest.WithdrawalStatusMessage
import com.reddio.crypto.CryptoService.Reddio
import com.reddio.fixtures.Fixtures
import com.reddio.fixtures.StarkKeysPool
import mu.KotlinLogging
import org.junit.Assert
import org.junit.Ignore
import org.junit.Test
import org.junit.experimental.categories.Category

private val logger = KotlinLogging.logger {}

@Ignore
@Category(IntegrationTest::class)
class DefaultReddioClientWithdrawalIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EtherscanNFTFetcher {
ethAddress: String, contractAddress: String = Fixtures.ReddioTestERC721ContractAddress
): List<Fixtures.Companion.ERC721Ownership> {
val url =
"https://api-goerli.etherscan.io/api?module=account&action=tokennfttx&contractaddress=$contractAddress&address=$ethAddress&startblock=0&endblock=9999999999&sort=asc&apikey=${fetchEtherscanAPIKey()}"
"https://api-sepolia.etherscan.io/api?module=account&action=tokennfttx&contractaddress=$contractAddress&address=$ethAddress&startblock=0&endblock=9999999999&sort=asc&apikey=${fetchEtherscanAPIKey()}"

val req = Request.Builder().get().url(url).build()
val response: EtherscanTokenTransferEvents = httpClient.newCall(req).execute().let { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class Fixtures {
web3j,
Credentials.create(it.ethPrivateKey),
StaticGasLimitSuggestionPriceGasProvider(
DefaultEthereumInteraction.GOERIL_ID, GasOption.Market, BigInteger.valueOf(100000L)
DefaultEthereumInteraction.SEPOLIA_ID, GasOption.Market, BigInteger.valueOf(100000L)
)
)
val erc20Balance = contract.balanceOf(it.ethAddress).send()
Expand Down
Loading
Loading