Skip to content

Commit

Permalink
Consider 'icon' platform when openBTPNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
sink772 committed Jul 17, 2023
1 parent d45d7b3 commit 3e18ffa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public interface ChainScore {
@External(readonly=true)
byte[] getBTPPublicKey(Address address, String name);

@External
void setPRepNodePublicKey(byte[] pubKey);

@External(readonly=true)
byte[] getPRepNodePublicKey(Address address);

@External(readonly=true)
long getBTPNetworkTypeID(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import foundation.icon.score.util.StringUtil;
import org.junit.jupiter.api.Tag;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -43,8 +43,12 @@ public interface MockGovIntegrationTest {
ChainScore chainScore = chainScoreClient;

static long openBTPNetwork(String networkTypeName, String name, score.Address owner) {
ensureRevision();
ensureBTPPublicKey();
@SuppressWarnings("unchecked")
Map<String, Object> netInfo = mockGovClient.request(Map.class, "icx_getNetworkInfo", null);
final String platform = (String) netInfo.getOrDefault("platform", "basic");

ensureRevision(platform);
ensureBTPPublicKey(platform);
AtomicLong networkId = new AtomicLong();

mockGovClient.openBTPNetwork(chainScoreClient.BTPNetworkOpened((l) -> {
Expand All @@ -64,24 +68,46 @@ static void closeBTPNetwork(long networkId) {
networkId);
}

static void ensureRevision() {
final int revision = 9;
static void ensureRevision(String platform) {
final int revision;
switch (platform) {
case "icon":
revision = 21;
break;
case "basic":
default:
revision = 9;
}
if (revision != chainScore.getRevision()) {
mockGov.setRevision(revision);
}
}

static void ensureBTPPublicKey() {
static void ensureBTPPublicKey(String platform) {
String DSA = "ecdsa/secp256k1";
Address address = validatorWallet.getAddress();
byte[] pubKey = chainScore.getBTPPublicKey(address, DSA);
byte[] pubKey;
switch (platform) {
case "icon":
pubKey = chainScore.getPRepNodePublicKey(address);
break;
case "basic":
default:
pubKey = chainScore.getBTPPublicKey(address, DSA);
}
System.out.println("getPublicKey:" + StringUtil.bytesToHex(pubKey));

if (pubKey == null) {
pubKey = validatorWallet.getPublicKey();
System.out.println("setBTPPublicKey:" + StringUtil.bytesToHex(pubKey));
chainScore.setBTPPublicKey(DSA, pubKey);
switch (platform) {
case "icon":
chainScore.setPRepNodePublicKey(pubKey);
break;
case "basic":
default:
chainScore.setBTPPublicKey(DSA, pubKey);
}
}
}


}

0 comments on commit 3e18ffa

Please sign in to comment.