Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
env:
ENABLE_LOGS: true
NETWORK: local
ENABLE_SOROBAN_RPC: true
PROTOCOL_VERSION: 28
ENABLE: core,rpc
PROTOCOL_VERSION: 30
options: >-
--health-cmd "curl --no-progress-meter --fail-with-body -X POST \"http://localhost:8000/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getNetwork\"}' && curl --no-progress-meter \"http://localhost:8000/friendbot\" | grep '\"invalid_field\": \"addr\"'"
--health-cmd "curl --no-progress-meter -X POST \"http://localhost:8000/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getHealth\"}' | grep '\"status\":\"healthy\"' && curl --no-progress-meter \"http://localhost:8000/friendbot\" | grep '\"invalid_field\": \"addr\"'"
--health-interval 10s
--health-timeout 5s
--health-retries 50
Expand Down
32 changes: 27 additions & 5 deletions src/test/java/org/stellar/sdk/IntegrationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import org.stellar.sdk.operations.ChangeTrustOperation;
import org.stellar.sdk.operations.InvokeHostFunctionOperation;
import org.stellar.sdk.operations.PaymentOperation;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse;
import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse;
import org.stellar.sdk.scval.Scv;
import org.stellar.sdk.xdr.SCVal;

public class IntegrationUtils {
public static final String RPC_URL = "http://127.0.0.1:8000/rpc";
public static final String HORIZON_URL = "http://127.0.0.1:8000";
public static final String FRIEND_BOT_URL = "http://127.0.0.1:8000/friendbot";
public static final Network NETWORK = Network.STANDALONE;

Expand Down Expand Up @@ -140,8 +140,8 @@ public static BigInteger getBalanceForContract(String contractId, Asset asset, K
public static void issueAsset(
String assetCode, KeyPair issuer, KeyPair receiver, BigDecimal amount) {
Asset asset = Asset.createNonNativeAsset(assetCode, issuer.getAccountId());
try (Server server = new Server(HORIZON_URL)) {
AccountResponse issuerAccount = server.accounts().account(issuer.getAccountId());
try (SorobanServer server = new SorobanServer(RPC_URL)) {
TransactionBuilderAccount issuerAccount = server.getAccount(issuer.getAccountId());

Transaction transaction =
new TransactionBuilder(issuerAccount, NETWORK)
Expand All @@ -164,7 +164,29 @@ public static void issueAsset(

transaction.sign(issuer);
transaction.sign(receiver);
server.submitTransaction(transaction);
submitTransaction(transaction);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/** Submits the transaction via RPC and waits until it succeeds, throwing otherwise. */
public static GetTransactionResponse submitTransaction(Transaction transaction) {
try (SorobanServer server = new SorobanServer(RPC_URL)) {
SendTransactionResponse sendResponse = server.sendTransaction(transaction);
if (sendResponse.getStatus() != SendTransactionResponse.SendTransactionStatus.PENDING) {
throw new RuntimeException("Transaction submission failed: " + sendResponse);
}
GetTransactionResponse getResponse = server.pollTransaction(sendResponse.getHash());
if (getResponse.getStatus() != GetTransactionResponse.GetTransactionStatus.SUCCESS) {
throw new RuntimeException("Transaction failed: " + getResponse);
}
return getResponse;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
}
50 changes: 25 additions & 25 deletions src/test/java/org/stellar/sdk/TransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,16 +515,16 @@ public void testIntegrationPaymentToContractTransactionWithNativeAsset() throws
IntegrationUtils.fundAccount(kp.getAccountId());
IntegrationUtils.createAssetContract(asset, kp);
String destination = IntegrationUtils.getRandomContractId(kp);
Server server = new Server(IntegrationUtils.HORIZON_URL);
TransactionBuilderAccount sourceAccount = server.loadAccount(kp.getAccountId());
SorobanServer server = new SorobanServer(IntegrationUtils.RPC_URL);
TransactionBuilderAccount sourceAccount = server.getAccount(kp.getAccountId());

Transaction transaction1 =
new TransactionBuilder(sourceAccount, IntegrationUtils.NETWORK)
.setBaseFee(100)
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount1, null);
transaction1.sign(kp);
server.submitTransaction(transaction1);
IntegrationUtils.submitTransaction(transaction1);
BigInteger balance1 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(1001250000L, balance1.longValue());

Expand All @@ -534,7 +534,7 @@ public void testIntegrationPaymentToContractTransactionWithNativeAsset() throws
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount2, null);
transaction2.sign(kp);
server.submitTransaction(transaction2);
IntegrationUtils.submitTransaction(transaction2);
BigInteger balance2 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(2209141000L, balance2.longValue());

Expand All @@ -544,7 +544,7 @@ public void testIntegrationPaymentToContractTransactionWithNativeAsset() throws
.setTimeout(300)
.buildRestoreAssetBalanceEntryTransaction(destination, asset, null);
transaction3.sign(kp);
server.submitTransaction(transaction3);
IntegrationUtils.submitTransaction(transaction3);

server.close();
}
Expand All @@ -562,16 +562,16 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum4Asset() thro
IntegrationUtils.issueAsset("CAT", issuerKp, kp, new BigDecimal("1000"));
IntegrationUtils.createAssetContract(asset, kp);
String destination = IntegrationUtils.getRandomContractId(kp);
Server server = new Server(IntegrationUtils.HORIZON_URL);
TransactionBuilderAccount sourceAccount = server.loadAccount(kp.getAccountId());
SorobanServer server = new SorobanServer(IntegrationUtils.RPC_URL);
TransactionBuilderAccount sourceAccount = server.getAccount(kp.getAccountId());

Transaction transaction1 =
new TransactionBuilder(sourceAccount, IntegrationUtils.NETWORK)
.setBaseFee(100)
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount1, null);
transaction1.sign(kp);
server.submitTransaction(transaction1);
IntegrationUtils.submitTransaction(transaction1);
BigInteger balance1 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(1001250000L, balance1.longValue());

Expand All @@ -581,7 +581,7 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum4Asset() thro
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount2, null);
transaction2.sign(kp);
server.submitTransaction(transaction2);
IntegrationUtils.submitTransaction(transaction2);
BigInteger balance2 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(2209141000L, balance2.longValue());

Expand All @@ -591,7 +591,7 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum4Asset() thro
.setTimeout(300)
.buildRestoreAssetBalanceEntryTransaction(destination, asset, null);
transaction3.sign(kp);
server.submitTransaction(transaction3);
IntegrationUtils.submitTransaction(transaction3);

server.close();
}
Expand All @@ -609,16 +609,16 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum12Asset() thr
IntegrationUtils.issueAsset("BANANA", issuerKp, kp, new BigDecimal("1000"));
IntegrationUtils.createAssetContract(asset, kp);
String destination = IntegrationUtils.getRandomContractId(kp);
Server server = new Server(IntegrationUtils.HORIZON_URL);
TransactionBuilderAccount sourceAccount = server.loadAccount(kp.getAccountId());
SorobanServer server = new SorobanServer(IntegrationUtils.RPC_URL);
TransactionBuilderAccount sourceAccount = server.getAccount(kp.getAccountId());

Transaction transaction1 =
new TransactionBuilder(sourceAccount, IntegrationUtils.NETWORK)
.setBaseFee(100)
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount1, null);
transaction1.sign(kp);
server.submitTransaction(transaction1);
IntegrationUtils.submitTransaction(transaction1);
BigInteger balance1 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(1001250000L, balance1.longValue());

Expand All @@ -628,7 +628,7 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum12Asset() thr
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount2, null);
transaction2.sign(kp);
server.submitTransaction(transaction2);
IntegrationUtils.submitTransaction(transaction2);
BigInteger balance2 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(2209141000L, balance2.longValue());

Expand All @@ -638,7 +638,7 @@ public void testIntegrationPaymentToContractTransactionWithAlphanum12Asset() thr
.setTimeout(300)
.buildRestoreAssetBalanceEntryTransaction(destination, asset, null);
transaction3.sign(kp);
server.submitTransaction(transaction3);
IntegrationUtils.submitTransaction(transaction3);

server.close();
}
Expand All @@ -654,16 +654,16 @@ public void testIntegrationPaymentToContractTransactionWithAssetIssuerAsSender()
Asset asset = Asset.createNonNativeAsset("CAT", kp.getAccountId());
IntegrationUtils.createAssetContract(asset, kp);
String destination = IntegrationUtils.getRandomContractId(kp);
Server server = new Server(IntegrationUtils.HORIZON_URL);
TransactionBuilderAccount sourceAccount = server.loadAccount(kp.getAccountId());
SorobanServer server = new SorobanServer(IntegrationUtils.RPC_URL);
TransactionBuilderAccount sourceAccount = server.getAccount(kp.getAccountId());

Transaction transaction1 =
new TransactionBuilder(sourceAccount, IntegrationUtils.NETWORK)
.setBaseFee(100)
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount1, null);
transaction1.sign(kp);
server.submitTransaction(transaction1);
IntegrationUtils.submitTransaction(transaction1);
BigInteger balance1 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(1001250000L, balance1.longValue());

Expand All @@ -673,7 +673,7 @@ public void testIntegrationPaymentToContractTransactionWithAssetIssuerAsSender()
.setTimeout(300)
.buildPaymentToContractTransaction(destination, asset, amount2, null);
transaction2.sign(kp);
server.submitTransaction(transaction2);
IntegrationUtils.submitTransaction(transaction2);
BigInteger balance2 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(2209141000L, balance2.longValue());

Expand All @@ -683,7 +683,7 @@ public void testIntegrationPaymentToContractTransactionWithAssetIssuerAsSender()
.setTimeout(300)
.buildRestoreAssetBalanceEntryTransaction(destination, asset, null);
transaction3.sign(kp);
server.submitTransaction(transaction3);
IntegrationUtils.submitTransaction(transaction3);

server.close();
}
Expand All @@ -700,8 +700,8 @@ public void testIntegrationPaymentToContractTransactionWithDifferentSource() thr
IntegrationUtils.fundAccount(opSource.getAccountId());
IntegrationUtils.createAssetContract(asset, kp);
String destination = IntegrationUtils.getRandomContractId(kp);
Server server = new Server(IntegrationUtils.HORIZON_URL);
TransactionBuilderAccount sourceAccount = server.loadAccount(kp.getAccountId());
SorobanServer server = new SorobanServer(IntegrationUtils.RPC_URL);
TransactionBuilderAccount sourceAccount = server.getAccount(kp.getAccountId());

Transaction transaction1 =
new TransactionBuilder(sourceAccount, IntegrationUtils.NETWORK)
Expand All @@ -711,7 +711,7 @@ public void testIntegrationPaymentToContractTransactionWithDifferentSource() thr
destination, asset, amount1, opSource.getAccountId());
transaction1.sign(kp);
transaction1.sign(opSource);
server.submitTransaction(transaction1);
IntegrationUtils.submitTransaction(transaction1);
BigInteger balance1 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(1001250000L, balance1.longValue());

Expand All @@ -723,7 +723,7 @@ public void testIntegrationPaymentToContractTransactionWithDifferentSource() thr
destination, asset, amount2, opSource.getAccountId());
transaction2.sign(kp);
transaction2.sign(opSource);
server.submitTransaction(transaction2);
IntegrationUtils.submitTransaction(transaction2);
BigInteger balance2 = IntegrationUtils.getBalanceForContract(destination, asset, kp);
assertEquals(2209141000L, balance2.longValue());

Expand All @@ -734,7 +734,7 @@ public void testIntegrationPaymentToContractTransactionWithDifferentSource() thr
.buildRestoreAssetBalanceEntryTransaction(destination, asset, opSource.getAccountId());
transaction3.sign(kp);
transaction3.sign(opSource);
server.submitTransaction(transaction3);
IntegrationUtils.submitTransaction(transaction3);

server.close();
}
Expand Down
Loading