Skip to content

Commit 90a4217

Browse files
committed
test(runtime): add DOT integration tests (runtimeVersion + account storage) with logging and network guards; docs: strengthen testing and local.properties guidance
1 parent c14c735 commit 90a4217

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
- Run: module `testDebugUnitTest` (or `testDevelopDebugUnitTest`), or root `runTest`.
4444
- Coverage: maintain/raise JaCoCo coverage for changed code.
4545
- New code policy: every time you add a function, create at least one unit test for it (minimum), placed in the corresponding module under `src/test`.
46+
- Integration (DOT): add instrumentation/integration tests that hit a reachable Polkadot node and log key responses (e.g., runtimeVersion, balances, fees). Guard with assumptions so tests skip when network is unavailable.
47+
- Logs: when testing DOT, log the raw RPC response and parsed model to aid debugging; never log secrets.
4648

4749
## Commit & Pull Requests
4850
- Commits: imperative, concise subject; reference issues (`#123`). Prefer Conventional Commits (`feat:`, `fix:`, `refactor:`) when possible.
@@ -67,6 +69,12 @@
6769
- Create a root-level `local.properties` with the required secrets and service credentials. Do NOT commit this file.
6870
- See `docs/samples/local.properties.example` and create a private `local.properties` at the repo root; replace placeholders with your real values.
6971
- Typical keys include: MoonPay, PayWings (Sora Card), X1 plugin, Google Web Client IDs, Ethereum providers (Blast, Etherscan/BscScan/PolygonScan/OKLink), WalletConnect, Alchemy, Dwellir, TON API.
72+
- Formats: use `key=value` per line; avoid trailing spaces. Strings may be unquoted; if values contain special characters or spaces, wrap in double quotes. Set `sdk.dir=/absolute/path/to/Android/sdk` to avoid SDK lookup errors.
73+
- Runtime overrides (mirrors recommended for first run):
74+
- `TYPES_URL_OVERRIDE=https://cdn.jsdelivr.net/gh/soramitsu/shared-features-utils@master/chains/all_chains_types_android.json`
75+
- `DEFAULT_V13_TYPES_URL_OVERRIDE=https://cdn.jsdelivr.net/gh/soramitsu/shared-features-utils@master/chains/default_v13_types.json`
76+
- `CHAINS_URL_OVERRIDE=https://cdn.jsdelivr.net/gh/soramitsu/shared-features-utils@master/chains/v13/chains.json`
77+
- Verify config: `./gradlew printPolkadotSdkAlignment` prints effective URLs and any shared_features pin before you run the app/tests.
7078

7179
## Utils Integration
7280
- Gradle maps the GitHub repo `soramitsu/fearless-utils-Android` as a source dependency and builds `jp.co.soramitsu.fearless-utils:fearless-utils` from source (requires network).
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package jp.co.soramitsu.runtime.integration
2+
3+
import android.util.Log
4+
import org.junit.Assume.assumeTrue
5+
import org.junit.Test
6+
import java.io.BufferedReader
7+
import java.io.OutputStreamWriter
8+
import java.net.HttpURLConnection
9+
import java.net.URL
10+
11+
/**
12+
* Balance integration logger for Polkadot (DOT).
13+
* This test logs the raw result of `state_getStorage` for a provided System.Account storage key.
14+
*
15+
* Usage:
16+
* - Provide a reachable RPC URL via system property or env var `DOT_RPC_URL`.
17+
* - Provide a precomputed storage key for System.Account(<SS58 accountId>) via `DOT_ACCOUNT_STORAGE_KEY`.
18+
* The key is SCALE-encoded and hashed as per substrate (pallet: "System", storage: "Account").
19+
* - Example run:
20+
* ./gradlew \
21+
* -Pandroid.testInstrumentationRunnerArguments.DOT_RPC_URL=https://polkadot-rpc.publicnode.com \
22+
* -Pandroid.testInstrumentationRunnerArguments.DOT_ACCOUNT_STORAGE_KEY=0x26aa394eea5630e07c48ae0c9558cef702a5...
23+
* :runtime:connectedDebugAndroidTest
24+
*/
25+
class DotBalanceIntegrationTest {
26+
27+
private fun hasNetwork(): Boolean = try {
28+
val url = URL("https://www.google.com/generate_204")
29+
(url.openConnection() as HttpURLConnection).run {
30+
connectTimeout = 2000
31+
readTimeout = 2000
32+
requestMethod = "GET"
33+
connect()
34+
val ok = responseCode in 200..399
35+
disconnect()
36+
ok
37+
}
38+
} catch (_: Exception) { false }
39+
40+
@Test
41+
fun testPolkadotAccountStorage_logsResponseOrSkips() {
42+
assumeTrue("No network; skipping", hasNetwork())
43+
44+
val rpcUrl = System.getProperty("DOT_RPC_URL")
45+
?: System.getenv("DOT_RPC_URL")
46+
?: "https://polkadot-rpc.publicnode.com"
47+
48+
val storageKey = System.getProperty("DOT_ACCOUNT_STORAGE_KEY") ?: System.getenv("DOT_ACCOUNT_STORAGE_KEY")
49+
assumeTrue("No DOT_ACCOUNT_STORAGE_KEY provided; skipping", !storageKey.isNullOrBlank())
50+
51+
val payload = """
52+
{"jsonrpc":"2.0","method":"state_getStorage","params":["$storageKey"],"id":2}
53+
""".trimIndent()
54+
55+
val response = httpPost(rpcUrl, payload)
56+
Log.i("DotBalanceIntegrationTest", "RPC URL: $rpcUrl")
57+
Log.i("DotBalanceIntegrationTest", "state_getStorage(Account) => $response")
58+
59+
// Basic sanity: expect non-empty hex or null
60+
assumeTrue("Unexpected storage response", response.contains("result"))
61+
}
62+
63+
private fun httpPost(urlStr: String, body: String): String {
64+
val url = URL(urlStr)
65+
val conn = (url.openConnection() as HttpURLConnection).apply {
66+
requestMethod = "POST"
67+
connectTimeout = 5000
68+
readTimeout = 10000
69+
doOutput = true
70+
setRequestProperty("Content-Type", "application/json")
71+
}
72+
73+
OutputStreamWriter(conn.outputStream, Charsets.UTF_8).use { it.write(body) }
74+
75+
val code = conn.responseCode
76+
val stream = if (code in 200..299) conn.inputStream else conn.errorStream
77+
val text = BufferedReader(stream.reader(Charsets.UTF_8)).use { it.readText() }
78+
conn.disconnect()
79+
return text
80+
}
81+
}
82+

0 commit comments

Comments
 (0)