Skip to content

Commit

Permalink
feat: #372 Add method to get script DRepId and tests (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Jan 30, 2024
1 parent 2e18814 commit ac405d5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,14 @@ void testPubKeyFromParentPubKey() {

assertThat(publicKey.getKeyData()).isEqualTo(childHdKeyPair.getPublicKey().getKeyData());
}

@Test
void testDRepId() {
String mnemonicPhrase = "punch smile segment tumble sauce oak mosquito clay service switch still federal chicken economy saddle galaxy reunion trust dinosaur demise illegal pupil trip lyrics";

Account account = new Account(Networks.testnet(), mnemonicPhrase);
String drepId = account.drepId();

assertThat(drepId).isEqualTo("drep18hf6wcv9aaq426duj8kcc5kp9pauz9ac8znh8jmckm80sf7fetw");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class DRepId {
public static final String DREP_ID_PREFIX = "drep";
public static final String DREP_ID_SCRIPT_PREFIX = "drep_script";

public static String fromVerificationKey(VerificationKey verificationKey) {
String keyHash = KeyGenUtil.getKeyHash(verificationKey);
Expand All @@ -27,6 +28,11 @@ public static String fromKeyHash(String keyHash) {
return drepId;
}

public static String fromScriptHash(String scriptHash) {
String drepId = Bech32.encode(HexUtil.decodeHexString(scriptHash), DREP_ID_SCRIPT_PREFIX);
return drepId;
}

public static DRep toDrep(String drepId, DRepType drepType) {
byte[] bytes = Bech32.decode(drepId).data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ void fromVerificationKeyBytes() {
assertThat(drepId).isEqualTo("drep1vlmeg4vu96detgkf5srw427363svqemth2xde2e2xp5ywfsx2gn");
}

@Test
void fromKeyHash() {
String drepId = DRepId.fromKeyHash("74984fae4ca1715fa1f8759f9d871015ac87f449a85dea6cf9956da1");
assertThat(drepId).isEqualTo("drep1wjvyltjv59c4lg0cwk0empcszkkg0azf4pw75m8ej4k6zuqfvt5");
}

@Test
void fromScriptHash() {
String drepId = DRepId.fromScriptHash("41868c2b4e5289022a3a1f6f47f86823bc605c609d2c47a2db58e04a");
assertThat(drepId).isEqualTo("drep_script1gxrgc26w22ysy236rah507rgyw7xqhrqn5ky0gkmtrsy553rrq7");
}

//TODO: Implement this
@Test
void toDrep() {
Expand Down

0 comments on commit ac405d5

Please sign in to comment.