Skip to content

Commit

Permalink
feat: add getTransaction api
Browse files Browse the repository at this point in the history
Signed-off-by: grapebaba <281165273@qq.com>
  • Loading branch information
GrapeBaBa committed Nov 12, 2022
1 parent 18ef061 commit d4ead10
Show file tree
Hide file tree
Showing 45 changed files with 4,456 additions and 494 deletions.
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ dependencies {
testImplementation 'com.squareup.okhttp3:mockwebserver:4.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
// https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite-api
testImplementation 'org.junit.platform:junit-platform-suite-api:1.9.1'
// https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite-engine
testRuntimeOnly 'org.junit.platform:junit-platform-suite-engine:1.9.1'

testRuntimeOnly 'org.junit.platform:junit-platform-reporting:1.9.1'
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
finalizedBy jacocoTestReport
}

Expand Down Expand Up @@ -131,3 +140,13 @@ check {
dependsOn += jacocoTestCoverageVerification
// dependsOn += integrationTest
}

tasks.withType(Test).configureEach {
def outputDir = reports.junitXml.outputLocation
jvmArgumentProviders << ({
[
"-Djunit.platform.reporting.open.xml.enabled=true",
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}"
]
} as CommandLineArgumentProvider)
}
111 changes: 92 additions & 19 deletions src/integrationTest/java/io/sui/SuiClientImplIntTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@
import io.sui.jsonrpc.JsonRpc20Response.Error.ErrorCode;
import io.sui.jsonrpc.JsonRpcClientProvider;
import io.sui.jsonrpc.OkHttpJsonRpcClientProvider;
import io.sui.models.GetObjectResponse;
import io.sui.models.GetObjectResponse.ObjectIdResponseDetails;
import io.sui.models.ObjectStatus;
import io.sui.models.SuiApiException;
import io.sui.models.SuiData;
import io.sui.models.SuiObject;
import io.sui.models.SuiObjectInfo;
import io.sui.models.SuiObjectOwner;
import io.sui.models.SuiObjectOwner.AddressOwner;
import io.sui.models.SuiObjectRef;
import java.math.BigInteger;
import io.sui.models.events.CoinBalanceChangeEvent;
import io.sui.models.events.CoinBalanceChangeEvent.BalanceChangeType;
import io.sui.models.events.EventKind;
import io.sui.models.events.MoveEvent;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.GetObjectResponse.ObjectIdResponseDetails;
import io.sui.models.objects.ObjectStatus;
import io.sui.models.objects.SuiData;
import io.sui.models.objects.SuiObject;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.objects.SuiObjectOwner;
import io.sui.models.objects.SuiObjectOwner.AddressOwner;
import io.sui.models.objects.SuiObjectRef;
import io.sui.models.transactions.ExecutionStatus.ExecutionStatusType;
import io.sui.models.transactions.MoveCall;
import io.sui.models.transactions.TransactionKind;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -66,7 +73,7 @@ static void beforeAll() {
/**
* Gets object.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -90,7 +97,7 @@ void getObjectExistingMoveObject() throws ExecutionException, InterruptedExcepti
/**
* Gets object no exist.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -111,7 +118,7 @@ void getObjectNoExist() throws ExecutionException, InterruptedException {
/**
* Gets object invalid params.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -134,7 +141,7 @@ void getObjectInvalidParams() throws ExecutionException, InterruptedException {
/**
* Gets objects owned by address is not empty.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -155,7 +162,7 @@ void getObjectsOwnedByAddressIsNotEmpty() throws ExecutionException, Interrupted
/**
* Gets objects owned by object is empty.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -171,7 +178,7 @@ void getObjectsOwnedByObjectIsEmpty() throws ExecutionException, InterruptedExce
/**
* Gets raw object existing move object.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
Expand All @@ -195,13 +202,79 @@ void getRawObjectExistingMoveObject() throws ExecutionException, InterruptedExce
/**
* Gets total transaction number.
*
* @throws ExecutionException the execution exception
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test getTotalTransactionNumber.")
void getTotalTransactionNumber() throws ExecutionException, InterruptedException {
CompletableFuture<BigInteger> res = client.getTotalTransactionNumber();
assertEquals(BigInteger.valueOf(2L), res.get());
CompletableFuture<Long> res = client.getTotalTransactionNumber();
assertEquals(2L, res.get());
}

/**
* Gets transaction.
*
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test getTransaction.")
void getTransaction() throws ExecutionException, InterruptedException {
CompletableFuture<TransactionResponse> res =
client.getTransaction("3Dda4/74LXf6GmOxMxp3qdbW/WdQ6/8EHobZ1LvSyYk=");
TransactionResponse transactionResponse = res.get();
System.out.println(transactionResponse);
assertEquals(1, transactionResponse.getCertificate().getAuthSignInfo().getSignature().size());
assertEquals(
"g+aeuIw6zZ08o3PP+qX1G7h+KLfGSbM7Rk3ZLHu2QjbYhZViqRchJOhKVbZw0pQI",
transactionResponse.getCertificate().getAuthSignInfo().getSignature().get(0));
assertEquals(
"AIinOofScNIfh4XjXlN1fhtT4hFyQXDZsr72PBG731kC9Xl++yhAQSxZJqkvSPf3LOCQsLYxovYAXSut"
+ "4wb9uAefzp9vXA0ydchzCCVdlo/OyzDxzcQ/iCDrGuPfEkHJiA==",
transactionResponse.getCertificate().getTxSignature());
assertEquals(
"3Dda4/74LXf6GmOxMxp3qdbW/WdQ6/8EHobZ1LvSyYk=",
transactionResponse.getCertificate().getTransactionDigest());

assertEquals(1, transactionResponse.getCertificate().getData().getTransactions().size());
MoveCall call =
((TransactionKind.CallTransactionKind)
transactionResponse.getCertificate().getData().getTransactions().get(0))
.getCall();
assertEquals("devnet_nft", call.getModule());
assertEquals("mint", call.getFunction());
assertEquals(3, call.getArguments().size());
assertEquals(
"0x342950ba2451c2f27ed128e591c2b4551e5177c2",
transactionResponse.getCertificate().getData().getGasPayment().getObjectId());
assertEquals(
ExecutionStatusType.success, transactionResponse.getEffects().getStatus().getStatus());
assertEquals(
"3Dda4/74LXf6GmOxMxp3qdbW/WdQ6/8EHobZ1LvSyYk=",
transactionResponse.getEffects().getTransactionDigest());
assertEquals(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
((AddressOwner) transactionResponse.getEffects().getMutated().get(0).getOwner())
.getAddressOwner());
assertEquals(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
((AddressOwner) transactionResponse.getEffects().getCreated().get(0).getOwner())
.getAddressOwner());
assertEquals(
"0xb5e91320d3acc77b4d9e66a218031441b2be1bb3",
transactionResponse.getEffects().getCreated().get(0).getReference().getObjectId());
assertEquals(3, transactionResponse.getEffects().getEvents().size());
CoinBalanceChangeEvent coinBalanceChangeEvent =
((EventKind.CoinBalanceChangeEventKind) transactionResponse.getEffects().getEvents().get(0))
.getCoinBalanceChange();
assertEquals(BalanceChangeType.Gas, coinBalanceChangeEvent.getChangeType());
assertEquals(
"0x342950ba2451c2f27ed128e591c2b4551e5177c2", coinBalanceChangeEvent.getCoinObjectId());
MoveEvent moveEvent =
((EventKind.MoveEventKind) transactionResponse.getEffects().getEvents().get(2))
.getMoveEvent();
assertEquals(
"0xb5e91320d3acc77b4d9e66a218031441b2be1bb3", moveEvent.getFields().get("object_id"));
}
}
16 changes: 12 additions & 4 deletions src/main/java/io/sui/SuiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package io.sui;


import io.sui.models.GetObjectResponse;
import io.sui.models.SuiObjectInfo;
import java.math.BigInteger;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -68,5 +68,13 @@ public interface SuiClient {
*
* @return the total transaction number
*/
CompletableFuture<BigInteger> getTotalTransactionNumber();
CompletableFuture<Long> getTotalTransactionNumber();

/**
* Gets transaction.
*
* @param digest the digest
* @return the transaction
*/
CompletableFuture<TransactionResponse> getTransaction(String digest);
}
18 changes: 12 additions & 6 deletions src/main/java/io/sui/SuiClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import com.google.common.reflect.TypeToken;
import io.sui.jsonrpc.JsonRpc20Request;
import io.sui.jsonrpc.JsonRpcClientProvider;
import io.sui.models.GetObjectResponse;
import io.sui.models.SuiApiException;
import io.sui.models.SuiObjectInfo;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.TransactionResponse;
import java.lang.reflect.Type;
import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -81,11 +81,17 @@ public CompletableFuture<GetObjectResponse> getRawObject(String id) {
}

@Override
public CompletableFuture<BigInteger> getTotalTransactionNumber() {
public CompletableFuture<Long> getTotalTransactionNumber() {
final JsonRpc20Request request =
createJsonRpc20Request("sui_getTotalTransactionNumber", Lists.newArrayList());
return call(
"/sui_getTotalTransactionNumber", request, new TypeToken<BigInteger>() {}.getType());
return call("/sui_getTotalTransactionNumber", request, new TypeToken<Long>() {}.getType());
}

@Override
public CompletableFuture<TransactionResponse> getTransaction(String digest) {
final JsonRpc20Request request =
createJsonRpc20Request("sui_getTransaction", Lists.newArrayList(digest));
return call("/sui_getTransaction", request, new TypeToken<TransactionResponse>() {}.getType());
}

private JsonRpc20Request createJsonRpc20Request(String method, List<?> params) {
Expand Down
Loading

0 comments on commit d4ead10

Please sign in to comment.