Skip to content

Commit

Permalink
Merge pull request #40 from kaiachain/feat/base-unittest
Browse files Browse the repository at this point in the history
feat: base testing for web3py and web3j
  • Loading branch information
Sotatek-TanHoang authored Oct 2, 2024
2 parents 6f4b941 + d278233 commit f5d6aaa
Show file tree
Hide file tree
Showing 129 changed files with 889 additions and 245 deletions.
1 change: 1 addition & 0 deletions web3j-ext/web3j-ext/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.14.2'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.mockito:mockito-core:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'org.json:json:20230618'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class DecryptKeystoreV3Example implements keySample {

public static void run() throws Exception {
String password = "Iloveklaytn";
String password = "Ilovekaia";

String[] keyFiles = { "/Legacy_V3.json", "/Public_V3.json" };
for (String keyFile : keyFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class DecryptKeystoreV4Example implements keySample {

public static void run() throws Exception {
String password = "Iloveklaytn";
String password = "Ilovekaia";

String[] keyFiles = { "/RoleBased_V4.json", "/Multi_V4.json", "/Public_V4.json" };
for (String keyFile : keyFiles) {
Expand Down
20 changes: 10 additions & 10 deletions web3j-ext/web3j-ext/src/main/resources/Legacy_V3.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"address": "a2a8854b1802d8cd5de631e690817c253d6a9153",
"id": "4459e0d8-93be-4c65-b44f-3dcea47b54a1",
"version": 3,
"id": "1966f7fd-04cf-4e69-8b57-95f0e15ee7fe",
"address": "0xa2a8854b1802d8cd5de631e690817c253d6a9153",
"crypto": {
"ciphertext": "ee49c9aa1dfc1ca29cb4054bc56179b25b88b883c7d07d37328ef2a82707aa37",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "719daf4baf464d2f207dcde23ae69dde"
"iv": "dd8d15c77b440974169e13ba902e289e"
},
"cipher": "aes-128-ctr",
"ciphertext": "d6b33f73022e00ab6d0ef20726ecbe5e0d6a9f6f05738d46cf91457ceeba300d",
"kdf": "scrypt",
"kdfparams": {
"salt": "68aee420df049cc6a9d9e12ebe352bad745142d55bfb9cc447c957d150d947af",
"n": 131072,
"dklen": 32,
"salt": "31993d471d09cbdb609f14fee9913177a8536a510787bbe024d2c6a749d9db60",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "e499623cbe2fde3373deb03d3f438f95959f84d9d59c304c86070c17569e383a"
"mac": "ae7d318bcf4cb77df5112624710e4efdbd9f88229337a265327e927a14830000"
}
}
48 changes: 24 additions & 24 deletions web3j-ext/web3j-ext/src/main/resources/Multi_V4.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@
"address": "0x82c6a8d94993d49cfd0c1d30f0f8caa65782cc7e",
"keyring": [
{
"ciphertext": "886853c592d16b2d38a18a7ee6b1bd2022b1191c8e89206e8c11e5538b3f814b",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "ceeab31b8827e241a2bf250b73b27285"
"iv": "4574beb59061ad7468bdc8eb34537b8a"
},
"cipher": "aes-128-ctr",
"ciphertext": "8ffd6e3a2117d302a73ada9e4dcf1f9fdb5abb7235c4f6fd0b68936a75e2dad7",
"kdf": "scrypt",
"kdfparams": {
"salt": "27d83dfb9c49cfccefae5c7331a4f394245e3efe0af4fe11d965d48f934c22bf",
"n": 131072,
"dklen": 32,
"salt": "0acb0532ca4664816d6943f536e7b1935b04329e9306ee112ca381de190a88b8",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "5b9884ca045d56b9863086f126eecf427e4538ffbfa76f015d32e057927a0f0e"
"mac": "da00139784fafee5bf386a1b07f29817611370827e3861ac1d888804fc79b8dd"
},
{
"ciphertext": "61bfbb38f728b32a5defbe2e36b04250e973987b0440a2a30f22552dfac01ea3",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "1b2f6914c98d62a02b74a686ddbcb992"
"iv": "daca766c9f465a51936989c9c50289ba"
},
"cipher": "aes-128-ctr",
"ciphertext": "68207226dbb6e7b999d15cefa7a28cf64f77d362d12a8488eaf9d685f298db8d",
"kdf": "scrypt",
"kdfparams": {
"salt": "a671ac0a72c86d94e9594452417807e8dff260f59b1a99a42cbb2e8b019f7806",
"n": 131072,
"dklen": 32,
"salt": "84318760fbe438ce2142ffc24da58f79d870532d4fe90eadc582ad88939f9c80",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "156bce45310cc2a7b0e888b2d4e6d935de168475fdca833f34103fbea229c264"
"mac": "1d06107c9a5e6a6dcd4e4ba724d4a7c815bd5f5bcff42c5fe4e7c675ce448005"
},
{
"ciphertext": "54af3e0695a3e5eecf64d15d0329d93f504b815bc043e06172e36aac4583c2aa",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "ff34109a7360af1d79a8415b53f6f57a"
"iv": "f4110bfd86da032a30a57cbbfae0da12"
},
"cipher": "aes-128-ctr",
"ciphertext": "ed77cd42e1f908b5dd2c4c809c2121165d6e98c131d1a1218b7f3826a1de031e",
"kdf": "scrypt",
"kdfparams": {
"salt": "6e85cd8a111bbb56d34a4a7e89b7a3d5447094854ac0fc18c3e8fe3b3c564cbc",
"n": 131072,
"dklen": 32,
"salt": "5b293e4fc0655f5c4ca360b017b8098089beab8df64955f4f86295c186e26034",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "22fc08cb12d508744af7767fda9ccf56078f98fa926e5b62112feea839cd7182"
"mac": "dabe400a32f21bc085028979f8767be7c47e3b0d8d210e0df01fbe95a0a94a90"
}
]
}
40 changes: 20 additions & 20 deletions web3j-ext/web3j-ext/src/main/resources/Public_V3.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"version": 3,
"id": "ced74d01-9e19-4f72-8aa8-ea95430ca238",
"address": "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b",
"crypto": {
"ciphertext": "c16a1768b399fe8533a33f527b8aa1a00a1a718586608e2e0bc0b6bdd0dac208",
"cipherparams": {
"iv": "f490dd33cad381d0b00f3412f3136eb7"
},
"cipher": "aes-128-ctr",
"kdf": "scrypt",
"kdfparams": {
"dklen": 32,
"salt": "e37aec3ea5e9cb4c1a5f253427721a979d247405c5c34a536db7bae2fa3b7df1",
"n": 4096,
"r": 8,
"p": 1
},
"mac": "6da0b34f47c3344c9628fe2eb757bfc42018552e78cf30ad211f21ee5909b11b"
}
}
"version": 3,
"id": "dc228b64-ae1e-4776-8b13-5ac5d7d218f6",
"address": "a2a8854b1802d8cd5de631e690817c253d6a9153",
"crypto": {
"ciphertext": "680a9af1dac1304bb4528f4a9f3f99162640850ed1126ae34d1727aab86c296b",
"cipherparams": {
"iv": "26e1eb656892ecfb576c05504dfe91f5"
},
"cipher": "aes-128-ctr",
"kdf": "scrypt",
"kdfparams": {
"n": 8192,
"r": 8,
"p": 1,
"dklen": 32,
"salt": "ae4623b3571a686deccfd8aef081d6ff1328489a7fe3e788f4e9c2560edce3e5"
},
"mac": "cfe014b19812af4a39c7302718f52b85bf3e50fc483c800129ea59daaec2bd11"
}
}
38 changes: 18 additions & 20 deletions web3j-ext/web3j-ext/src/main/resources/Public_V4.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"version": 4,
"id": "fa42ad5d-d8bf-4508-8e30-b1ff6f6f659a",
"address": "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b",
"keyring": [
{
"ciphertext": "a6e941470090476fd37a72c82c789de8ceece73bef9272ff994166a62295dc2b",
"cipherparams": {
"iv": "eae71af6f63ea0142a9a744cf50dabd6"
},
"cipher": "aes-128-ctr",
"kdf": "scrypt",
"kdfparams": {
"dklen": 32,
"salt": "40b7a6a1b20799e17efd7682cd37a2f5305b628ecf5ced72913ea2d6f29ddd9e",
"n": 4096,
"r": 8,
"p": 1
},
"mac": "c94f50c185d3fb8faa55ee6e285a3373684d3454529fd043a54217b0095a80ab"
}
]
"id": "04384fe3-1f19-4551-8f4c-2a48e9cca213",
"address": "a2a8854b1802d8cd5de631e690817c253d6a9153",
"keyring": [{
"ciphertext": "4b1e6c4d7ceb8913a3e5b6dce644cbbbf4b83172c9fa521a2ffb10087adec78a",
"cipherparams": {
"iv": "965cefe5668f0db8cf719d7e964d67f4"
},
"cipher": "aes-128-ctr",
"kdf": "scrypt",
"kdfparams": {
"n": 8192,
"r": 8,
"p": 1,
"dklen": 32,
"salt": "23a10a97c98fd0283462d5cf08a6b9218ec8f509fedfaf34a84f203f9e928678"
},
"mac": "6bbc7e1a3fe9369ba270dc3a6aeeaeb51c520d29ab75b3d3c3350c60d603b2d8"
}]
}
48 changes: 24 additions & 24 deletions web3j-ext/web3j-ext/src/main/resources/RoleBased_V4.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@
"keyring": [
[
{
"ciphertext": "992452cfa2b07e0e1494e6a9893db328ec77feb861a88ced36aafcc61834d86b",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "38d8fbb04aecc96a7eb588f8d057ac83"
"iv": "fac50c712f0ee4cbf995830514433085"
},
"cipher": "aes-128-ctr",
"ciphertext": "53f42c4f16cb8e8cddcd33a566e7d6b07615c59a4bc2ba185fbc0ceda5b78e25",
"kdf": "scrypt",
"kdfparams": {
"salt": "76498b572270309ef6fc360faa08d313ac6ca1f25bb16ddcf74745f208a93435",
"n": 131072,
"dklen": 32,
"salt": "9df721827cbff1dcd5b5a3985afccbb56ff84bb12022a59ee4b0ea37c24942da",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "6023d947acd1ebc8f34bae8a733b6405858e53f8c97f9c0336f98b6283e810ad"
"mac": "0dce36e7effe655df06fdfde9aa8c58353f13218ffdbf4ec743aa47033335ac1"
}
],
[
{
"ciphertext": "38ee5237a23582afac237754186826871eefa1aa39fb399f1ee1a65bd9c718ad",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "e001671a06e858d73d909ba46fe19b9c"
"iv": "2f84b60ea850050d2efaff45eb9c9de1"
},
"cipher": "aes-128-ctr",
"ciphertext": "bcecf3a4daa6bba3d48773df9b0d6dab1e7ea5f411493b655006f7a257ab6c55",
"kdf": "scrypt",
"kdfparams": {
"salt": "187577c7b884a88e8eb82c4a5ace49db33ebb60a8054a484a5f0e1fd54c3617b",
"n": 131072,
"dklen": 32,
"salt": "76aec3736e47b6a65f1bc9ade9671b543dbed97c1900ac425e833097751a165f",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "f650635cf9ea93d57a876f47a777f98463a8f588bb223d8dc169b601987c7f7c"
"mac": "e864602a136bfcf14d626bc3e89c668c93d27ae779616622a22cbcaea276a9ba"
}
],
[
{
"ciphertext": "6c206c11b728761cd37532dd22d4525e05da1048c174f163d5665ee7e5b5284b",
"cipher": "aes-128-ctr",
"cipherparams": {
"iv": "07455721fc33c9aaf7730197ec946207"
"iv": "ba5603d4ec2acca070a18a8dc38d38a3"
},
"cipher": "aes-128-ctr",
"ciphertext": "32f9c338e788cc6fe4f875805e5d9d227393b9ffbabd2f353426f18d9bff14ed",
"kdf": "scrypt",
"kdfparams": {
"salt": "c21a76f31c746599ecca8a347a0279234c2d99bce20d4e4528a33672161e3574",
"n": 131072,
"dklen": 32,
"salt": "b6bac6390f645eaf134a64cd401148c0e809897c29e8da1a7b3e33c3ed45e11a",
"n": 4096,
"r": 8,
"p": 1
"p": 1,
"r": 8
},
"mac": "83cc501c13f1397fb958cda7075e07cf388c417dd601ffb609cf4bc9e588ce02"
"mac": "ac3ee9cf09e54661a3d3f2eaa3a47b162053d486404af85ad3d3ee8aa9aac397"
}
]
]
Expand Down
32 changes: 32 additions & 0 deletions web3j-ext/web3j-ext/src/test/java/org/base/BaseTesting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.base;

import org.mockito.Mockito;
import org.web3j.crypto.KaiaCredentials;
import org.web3j.example.keySample;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.http.HttpService;
import org.web3j.protocol.kaia.Web3j;


public abstract class BaseTesting {
private final Web3jService web3jService = Mockito.mock(HttpService.class);
private final Web3j mockedWeb3j = Web3j.build(web3jService);
private final Web3j web3j = Web3j.build(new HttpService(keySample.BAOBAB_URL));
private final KaiaCredentials credentials = KaiaCredentials.create(keySample.LEGACY_KEY_privkey);

public Web3j getMockedWeb3j() {
return mockedWeb3j;
}

public Web3j getWeb3j() {
return web3j;
}

public Web3jService getWeb3jService() {
return web3jService;
}

public KaiaCredentials getCredentials() {
return credentials;
}
}
24 changes: 24 additions & 0 deletions web3j-ext/web3j-ext/src/test/java/org/base/UtilsHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.base;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

public class UtilsHelper {
public static String getResourceJSON(String resourcePath) throws IOException {
InputStream inputStream = UtilsHelper.class.getResourceAsStream(resourcePath);
if (inputStream == null) {
throw new IllegalArgumentException("resource not found: " + resourcePath);
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
return reader.lines().collect(Collectors.joining(System.lineSeparator()));

} catch (IOException e) {
throw e;
}
}
}
Loading

0 comments on commit f5d6aaa

Please sign in to comment.