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

feat:add split coin equal #36

Merged
merged 2 commits into from
Nov 26, 2022
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
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ dependencies {
}

test {
filter{
includeTestsMatching "*Suite"
}
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static void beforeAll() {
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test getSplitCoin.")
void getSplitCoin() throws ExecutionException, InterruptedException {
@DisplayName("Test splitCoin.")
void splitCoin() throws ExecutionException, InterruptedException {
CompletableFuture<TransactionBytes> res =
transactionBuilder.splitCoin(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
Expand All @@ -69,4 +69,23 @@ void getSplitCoin() throws ExecutionException, InterruptedException {
1000L);
System.out.println(res.get());
}

/**
* Split coin equal.
*
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test splitCoinEqual.")
void splitCoinEqual() throws ExecutionException, InterruptedException {
CompletableFuture<TransactionBytes> res =
transactionBuilder.splitCoinEqual(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
"0x7fbcb802d11d836a4034e7491bb544ddef460094",
5L,
null,
1000L);
System.out.println(res.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
* @author grapebaba
* @since 2022.11
*/
class SuiClientImplIntTests {
class QueryClientImplIntTests {

private static final String BASE_URL = "http://localhost:9000";

private static final JsonHandler jsonHandler = new GsonJsonHandler();

private static SuiClient client;
private static QueryClient client;

/** Before all. */
@BeforeAll
static void beforeAll() {
JsonRpcClientProvider jsonRpcClientProvider =
new OkHttpJsonRpcClientProvider(BASE_URL, jsonHandler);
client = new SuiClientImpl(jsonRpcClientProvider);
client = new QueryClientImpl(jsonRpcClientProvider);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/sui/JsonRpcTransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ public CompletableFuture<TransactionBytes> splitCoin(
return this.jsonRpcClientProvider.callAndUnwrapResponse(
"/sui_splitCoin", request, new TypeToken<TransactionBytes>() {}.getType());
}

@Override
public CompletableFuture<TransactionBytes> splitCoinEqual(
String signer, String coinObjectId, long splitCount, String gas, long gasBudget) {
final JsonRpc20Request request =
this.jsonRpcClientProvider.createJsonRpc20Request(
"sui_splitCoinEqual",
Lists.newArrayList(signer, coinObjectId, splitCount, gas, gasBudget));
return this.jsonRpcClientProvider.callAndUnwrapResponse(
"/sui_splitCoinEqual", request, new TypeToken<TransactionBytes>() {}.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author grapebaba
* @since 2022.11
*/
public interface SuiClient {
public interface QueryClient {

/**
* Gets object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author grapebaba
* @since 2022.11
*/
public class SuiClientImpl implements SuiClient {
public class QueryClientImpl implements QueryClient {

private final JsonRpcClientProvider jsonRpcClientProvider;

Expand All @@ -51,7 +51,7 @@ public class SuiClientImpl implements SuiClient {
*
* @param jsonRpcClientProvider the json rpc client provider
*/
public SuiClientImpl(JsonRpcClientProvider jsonRpcClientProvider) {
public QueryClientImpl(JsonRpcClientProvider jsonRpcClientProvider) {
this.jsonRpcClientProvider = jsonRpcClientProvider;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/sui/TransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ public interface TransactionBuilder {
*/
CompletableFuture<TransactionBytes> splitCoin(
String signer, String coinObjectId, List<Long> splitAmounts, String gas, Long gasBudget);

/**
* Split coin equal completable future.
*
* @param signer the signer
* @param coinObjectId the coin object id
* @param splitCount the split count
* @param gas the gas
* @param gasBudget the gas budget
* @return the completable future
*/
CompletableFuture<TransactionBytes> splitCoinEqual(
String signer, String coinObjectId, long splitCount, String gas, long gasBudget);
}
30 changes: 29 additions & 1 deletion src/test/java/io/sui/JsonRpcTransactionBuilderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.sui.jsonrpc.JsonRpcClientProvider;
import io.sui.jsonrpc.OkHttpJsonRpcClientProvider;
import io.sui.models.objects.InputObjectKind.ImmOrOwnedMoveObjectKind;
import io.sui.models.objects.InputObjectKind.MovePackageKind;
import io.sui.models.transactions.TransactionBytes;
import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -71,7 +72,11 @@ static MockWebServer createAndStartMockServer(int port) {
@Override
public MockResponse dispatch(RecordedRequest request) {
if ("/sui_splitCoin".equals(request.getPath())) {
return getMockResponse("mockdata/suiSplitCoin.json");
return getMockResponse("mockdata/splitCoin.json");
}

if ("/sui_splitCoinEqual".equals(request.getPath())) {
return getMockResponse("mockdata/splitCoinEqual.json");
}

return new MockResponse().setResponseCode(404);
Expand Down Expand Up @@ -150,4 +155,27 @@ void getSplitCoin() throws ExecutionException, InterruptedException {
.getImmOrOwnedMoveObject()
.getDigest());
}

/**
* Split coin equal.
*
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test splitCoinEqual.")
void splitCoinEqual() throws ExecutionException, InterruptedException {
CompletableFuture<TransactionBytes> res =
transactionBuilder.splitCoinEqual(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
"0x7fbcb802d11d836a4034e7491bb544ddef460094",
5L,
null,
1000L);
System.out.println(res.get());
assertEquals("0x24e6a45a16746213cc3aa152e2a6227857a580fa", res.get().getGas().getObjectId());
assertEquals(
"0x0000000000000000000000000000000000000002",
((MovePackageKind) res.get().getInputObjects().get(1)).getMovePackage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@
* @author grapebaba
* @since 2022.11
*/
class SuiClientImplTests {
class QueryClientImplTests {

private static final String BASE_URL = "http://localhost:9001";

private static final JsonHandler jsonHandler = new GsonJsonHandler();

private static SuiClient client;
private static QueryClient client;

private static MockWebServer mockWebServer;

Expand Down Expand Up @@ -236,7 +236,7 @@ public MockResponse dispatch(RecordedRequest request) {
static void beforeAll() {
JsonRpcClientProvider jsonRpcClientProvider =
new OkHttpJsonRpcClientProvider(BASE_URL, jsonHandler);
client = new SuiClientImpl(jsonRpcClientProvider);
client = new QueryClientImpl(jsonRpcClientProvider);
mockWebServer = createAndStartMockServer(9001);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/sui/SuiTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
* @since 2022.11
*/
@Suite
@SelectClasses({SuiClientImplTests.class, JsonRpcTransactionBuilderTests.class})
@SelectClasses({QueryClientImplTests.class, JsonRpcTransactionBuilderTests.class})
public class SuiTestSuite {}
31 changes: 31 additions & 0 deletions src/test/resources/mockdata/splitCoinEqual.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"jsonrpc": "2.0",
"result": {
"txBytes": "VHJhbnNhY3Rpb25EYXRhOjoAAgAAAAAAAAAAAAAAAAAAAAAAAAACAQAAAAAAAAAgrUd+yyNncmiOE+31Fz+w5YwHA+1hpiSfUqRnZJKhLN4DcGF5D2RpdmlkZV9hbmRfa2VlcAEHAAAAAAAAAAAAAAAAAAAAAAAAAAIDc3VpA1NVSQACAQB/vLgC0R2DakA050kbtUTd70YAlAAAAAAAAAAAIJfFaD7l53LPrBONn7W6V/cZK3jDOvYFQW2OPD3Rv4meAAgFAAAAAAAAAOp5Rk2GeGt6emPj8T95jyn15llHJOakWhZ0YhPMOqFS4qYieFelgPoAAAAAAAAAACBa0Zx/ukxCwIE7a4BAR4R3L2q2kICD45cvWWdBd26GhgEAAAAAAAAA6AMAAAAAAAA=",
"gas": {
"objectId": "0x24e6a45a16746213cc3aa152e2a6227857a580fa",
"version": 0,
"digest": "WtGcf7pMQsCBO2uAQEeEdy9qtpCAg+OXL1lnQXduhoY="
},
"inputObjects": [
{
"ImmOrOwnedMoveObject": {
"objectId": "0x7fbcb802d11d836a4034e7491bb544ddef460094",
"version": 0,
"digest": "l8VoPuXncs+sE42ftbpX9xkreMM69gVBbY48PdG/iZ4="
}
},
{
"MovePackage": "0x0000000000000000000000000000000000000002"
},
{
"ImmOrOwnedMoveObject": {
"objectId": "0x24e6a45a16746213cc3aa152e2a6227857a580fa",
"version": 0,
"digest": "WtGcf7pMQsCBO2uAQEeEdy9qtpCAg+OXL1lnQXduhoY="
}
}
]
},
"id": 1
}