Skip to content

Commit

Permalink
feat(javascore): implement IBCModule on xCall app (#228)
Browse files Browse the repository at this point in the history
* feat(javascore): implement IBCModule on xCall app
  • Loading branch information
redlarva authored Apr 12, 2023
1 parent 4325459 commit 72fce96
Show file tree
Hide file tree
Showing 23 changed files with 1,420 additions and 609 deletions.
21 changes: 21 additions & 0 deletions contracts/javascore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ subprojects {
}
}

dependencies {
compileOnly("foundation.icon:javaee-api:$javaeeVersion")
implementation("foundation.icon:javaee-scorex:$scorexVersion")

annotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
compileOnly("foundation.icon:javaee-score-client:$scoreClientVersion")

testImplementation 'com.google.protobuf:protobuf-javalite:3.13.0'
testImplementation 'foundation.icon:javaee-rt:0.9.3'
testImplementation("org.mockito:mockito-core:$mockitoCoreVersion")
testImplementation("org.mockito:mockito-inline:$mockitoCoreVersion")
testImplementation("foundation.icon:javaee-unittest:$javaeeUnittestVersion")
testAnnotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
testImplementation("foundation.icon:icon-sdk:$iconsdkVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterApiVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterParamsVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterEngineVersion")
}

configurations {
intTestImplementation.extendsFrom testImplementation
intTestAnnotationProcessor.extendsFrom testAnnotationProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

package foundation.icon.btp.xcall;
package ibc.icon.interfaces;

import foundation.icon.score.client.ScoreInterface;
import score.annotation.External;

public interface CallServiceReceiver {
@ScoreInterface
public interface ICallServiceReceiver {

/**
* Handles the call message received from the source chain.
Expand Down
44 changes: 44 additions & 0 deletions contracts/javascore/modules/mock-dapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version = '0.1.0'

dependencies {
implementation project(':lib')
implementation project(':score-util')
}

tasks.named('compileJava') {
dependsOn(':score-util:jar')
dependsOn(':lib:jar')
}

optimizedJar {
dependsOn(project(':lib').jar)
dependsOn(project(':score-util').jar)

mainClassName = 'ibc.mockapp.MockDApp'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}

deployJar {
endpoints {
berlin {
uri = 'https://berlin.net.solidwallet.io/api/v3'
nid = 0x7
}
lisbon {
uri = 'https://lisbon.net.solidwallet.io/api/v3'
nid = 0x2
}
local {
uri = 'http://localhost:9082/api/v3'
nid = 0x3
}
}
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
parameters {
arg('_callService', 'hxb6b5791be0b5ef67063b3c10b840fb81514db2fd')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package foundation.icon.btp.xcall.sample;
package ibc.mockapp;

import foundation.icon.btp.xcall.CallServiceReceiver;
import foundation.icon.score.client.ScoreClient;
import ibc.icon.interfaces.ICallServiceReceiver;
import java.math.BigInteger;
import score.Address;
import score.Context;
import score.DictDB;
Expand All @@ -28,18 +28,14 @@
import score.annotation.Optional;
import score.annotation.Payable;

import java.math.BigInteger;

@ScoreClient
public class DAppProxySample implements CallServiceReceiver {
public class MockDApp implements ICallServiceReceiver {
private final Address callSvc;
private final String callSvcBtpAddr;
private final VarDB<BigInteger> id = Context.newVarDB("id", BigInteger.class);
private final DictDB<BigInteger, RollbackData> rollbacks = Context.newDictDB("rollbacks", RollbackData.class);

public DAppProxySample(Address _callService) {
public MockDApp(Address _callService) {
this.callSvc = _callService;
this.callSvcBtpAddr = Context.call(String.class, this.callSvc, "getBtpAddress");
}

private void onlyCallService() {
Expand Down Expand Up @@ -81,12 +77,11 @@ private BigInteger _sendCallMessage(BigInteger value, String to, byte[] data, by
}
}

@Override
@External
public void handleCallMessage(String _from, byte[] _data) {
onlyCallService();
Context.println("handleCallMessage: from=" + _from + ", data=" + new String(_data));
if (callSvcBtpAddr.equals(_from)) {
if (Context.getAddress().equals(Address.fromString(_from))) {
// handle rollback data here
// In this example, just compare it with the stored one.
RollbackData received = RollbackData.fromBytes(_data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

package foundation.icon.btp.xcall.sample;
package ibc.mockapp;

import java.math.BigInteger;
import score.ByteArrayObjectWriter;
import score.Context;
import score.ObjectReader;
import score.ObjectWriter;

import java.math.BigInteger;

public class RollbackData {
private final BigInteger id;
private final byte[] rollback;
Expand Down
6 changes: 5 additions & 1 deletion contracts/javascore/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ project(':mockclient').name = "mockclient"

include(':mockapp')
project(':mockapp').projectDir = file("modules/mockapp")
project(':mockapp').name = "mockapp"
project(':mockapp').name = "mockapp"

include(':mock-dapp')
project(':mock-dapp').projectDir = file("modules/mock-dapp")
project(':mock-dapp').name = "mock-dapp"
53 changes: 42 additions & 11 deletions contracts/javascore/xcall/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
version = '0.1.0'

dependencies {
implementation project(':ibc')
compileOnly("foundation.icon:javaee-api:$javaeeVersion")
implementation("foundation.icon:javaee-scorex:$scorexVersion")
implementation project(':lib')
implementation project(':score-util')
testImplementation project(':test-lib')
}


// for generating ScoreClient
annotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
compileOnly("foundation.icon:javaee-score-client:$scoreClientVersion")
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}

testImplementation("foundation.icon:javaee-unittest:$javaeeUnittestVersion")
testAnnotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation("foundation.icon:javaee-score-client:$scoreClientVersion")
tasks.named('compileIntTestJava') {
dependsOn(':mock-dapp:optimizedJar')
}


optimizedJar {
dependsOn(project(':lib').jar)
dependsOn(project(':score-util').jar)
Expand All @@ -45,6 +52,30 @@ deployJar {
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
parameters {
arg('_ibc', 'hxb6b5791be0b5ef67063b3c10b840fb81514db2fd')
arg('_timeoutHeight', '0x3e8')
}
}


task integrationTest(type: Test) {
useJUnitPlatform()

rootProject.allprojects {
if (it.getTasks().findByName('optimizedJar')) {
dependsOn(it.getTasks().getByName('optimizedJar'))
}
}

options {
testLogging.showStandardStreams = true
description = 'Runs integration tests.'
group = 'verification'

testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath

systemProperty "java", optimizedJar.outputJarName
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* limitations under the License.
*/

package foundation.icon.btp.xcall;
package ibc.xcall.integration;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import foundation.icon.btp.xcall.data.CSMessageRequest;
import foundation.icon.btp.xcall.data.CSMessageResponse;

public class AssertCallService {
public static void assertEqualsCSMessageRequest(CSMessageRequest exp, CSMessageRequest got) {
assertEquals(exp.getFrom(), got.getFrom());
Expand Down
Loading

0 comments on commit 72fce96

Please sign in to comment.