Skip to content

Commit

Permalink
Move tests to main repo (#1551)
Browse files Browse the repository at this point in the history
* run tests on marathon

fix order

add unique build

remove unit tests

fix run tests

fix build tests

remove example test which lead to error

temp fix for build

remove example instrumental tests

adding debug lines

fix debug

fix path

fix build type

fix path

build debug version

fix path

run on github action

fix balances tests

store results in separate repo

fix artifacts path

fix artifact version

fix download path

fix path

fix path

update secrets

fix access

remove unnecessary checkout

update secrets

update storing folder

update deployment dir

* update deployment to gh-pages

* adding notification

* set event triggers

fix TestSigner
  • Loading branch information
stepanLav authored Jul 5, 2024
1 parent c2745e8 commit 54961eb
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 136 deletions.
52 changes: 52 additions & 0 deletions .github/scripts/run_balances_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
adb devices

# Install debug app
adb -s emulator-5554 install app/debug/app-debug.apk

# Install instrumental tests
adb -s emulator-5554 install test-app/androidTest/debug/app-debug-androidTest.apk

# Run tests
adb logcat -c &&
python - <<END
import os
import re
import subprocess as sp
import sys
import threading
import time
done = False
def update():
# prevent CI from killing the process for inactivity
while not done:
time.sleep(5)
print ("Running...")
t = threading.Thread(target=update)
t.dameon = True
t.start()
def run():
os.system('adb wait-for-device')
p = sp.Popen('adb shell am instrument -w -m -e debug false -e class "io.novafoundation.nova.balances.BalancesIntegrationTest" io.novafoundation.nova.debug.test/io.qameta.allure.android.runners.AllureAndroidJUnitRunner',
shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
return p.communicate()
success = re.compile(r'OK \(\d+ tests\)')
stdout, stderr = run()
stdout = stdout.decode('ISO-8859-1')
stderr = stderr.decode('ISO-8859-1')
done = True
print (stderr)
print (stdout)
if success.search(stderr + stdout):
sys.exit(0)
else:
sys.exit(1) # make sure we fail if the tests fail
END
EXIT_CODE=$?
adb logcat -d '*:E'

# Export results
adb exec-out run-as io.novafoundation.nova.debug sh -c 'cd /data/data/io.novafoundation.nova.debug/files && tar cf - allure-results' > allure-results.tar

exit $EXIT_CODE
52 changes: 52 additions & 0 deletions .github/scripts/run_instrumental_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
adb devices

# Install debug app
adb -s emulator-5554 install app/debug/app-debug.apk

# Install instrumental tests
adb -s emulator-5554 install test-app/androidTest/debug/app-debug-androidTest.apk

# Run tests
adb logcat -c &&
python - <<END
import os
import re
import subprocess as sp
import sys
import threading
import time
done = False
def update():
# prevent CI from killing the process for inactivity
while not done:
time.sleep(5)
print ("Running...")
t = threading.Thread(target=update)
t.dameon = True
t.start()
def run():
os.system('adb wait-for-device')
p = sp.Popen('adb shell am instrument -w -m -e notClass io.novafoundation.nova.balances.BalancesIntegrationTest -e package io.novafoundation.nova.debug io.novafoundation.nova.debug.test/io.qameta.allure.android.runners.AllureAndroidJUnitRunner',
shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
return p.communicate()
success = re.compile(r'OK \(\d+ tests\)')
stdout, stderr = run()
stdout = stdout.decode('ISO-8859-1')
stderr = stderr.decode('ISO-8859-1')
done = True
print (stderr)
print (stdout)
if success.search(stderr + stdout):
sys.exit(0)
else:
sys.exit(1) # make sure we fail if the tests fail
END
EXIT_CODE=$?
adb logcat -d '*:E'

# Export results
adb exec-out run-as io.novafoundation.nova.debug sh -c 'cd /data/data/io.novafoundation.nova.debug/files && tar cf - allure-results' > allure-results.tar

exit $EXIT_CODE
12 changes: 8 additions & 4 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ on:
required: false
type: string
default: "false"
upload-name:
required: false
type: string
default: "apk"
secrets:
ACALA_PROD_AUTH_TOKEN:
required: true
Expand Down Expand Up @@ -115,7 +119,7 @@ env:
CI_PRODUCTION_GOOGLE_SERVICES_FILE: ${{ secrets.CI_PRODUCTION_GOOGLE_SERVICES }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}-${{inputs.upload-name}}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -147,7 +151,7 @@ jobs:
uses: ./.github/workflows/install/

- name: 🧪 Run tests
if: ${{ inputs.run-tests }} == "true"
if: ${{ inputs.run-tests }}
run: ./gradlew runTest

- name: 🔐 Getting github sign key
Expand Down Expand Up @@ -176,7 +180,7 @@ jobs:

- name: ➡️ Upload build artifacts
if: ${{ !startsWith(inputs.gradlew-command, 'false') }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: apk
name: ${{ inputs.upload-name }}
path: app/build/outputs/apk/
109 changes: 109 additions & 0 deletions .github/workflows/balances_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Run balances tests

on:
workflow_dispatch:
schedule:
- cron: '0 */8 * * *'

jobs:
develop-build:
uses: novasamatech/nova-wallet-android/.github/workflows/android_build.yml@feat/move_tests_to_main_repo
with:
branch: ${{github.head_ref}}
gradlew-command: assembleDebug
upload-name: develop-apk
run-tests: false
secrets: inherit

test-build:
uses: novasamatech/nova-wallet-android/.github/workflows/android_build.yml@feat/move_tests_to_main_repo
with:
branch: ${{github.head_ref}}
gradlew-command: assembleDebugAndroidTest
upload-name: test-apk
run-tests: false
secrets: inherit

run-tests:
needs: [develop-build, test-build]
runs-on: macos-13
steps:
- uses: actions/checkout@v4

- name: Download built artifact
uses: actions/download-artifact@v4
with:
name: develop-apk
path: app

- name: Debug path
run: |
ls -laR app
- name: Download instrumential test artifact
uses: actions/download-artifact@v4
with:
name: test-apk
path: test-app

- name: Debug path
run: |
ls -laR test-app
- name: Add permissions
run: chmod +x .github/scripts/run_balances_test.sh

- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
disable-animations: true
profile: Nexus 6
api-level: 29
script: .github/scripts/run_balances_test.sh

- uses: actions/upload-artifact@v4
if: always()
with:
name: anroid-results
path: ./allure-results.tar

report:
needs: [run-tests]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Unzip results
run: |
find artifacts -name allure-results.tar -exec tar -xvf {} \;
- name: Debug path
run: |
ls -laR
- name: Generate report
uses: ./.github/workflows/report/
with:
token: ${{ secrets.ACTIONS_DEPLOY_KEY }}
keep-reports-history: 30

telegram-notification:
needs: [report]
runs-on: ubuntu-latest
if: failure()
steps:
- name: Notify Telegram channel
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: |
💸 Balances tests failed.
Results: https://novasamatech.github.io/balances_test_result/${{ github.run_id}}/index.html
40 changes: 40 additions & 0 deletions .github/workflows/report/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish report to gh-pages
description: That workflow will publish report to the github-pages
inputs:
keep-reports-history:
description: "History storage depth, integer"
required: true
token:
description: "Github PAT"
required: true

runs:
using: "composite"
steps:
- name: Get Allure history
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
repository: novasamatech/balances_test_result
ref: gh-pages
path: gh-pages

- name: Allure Report action
uses: simple-elf/allure-report-action@master
if: always()
with:
allure_results: allure-results
allure_history: allure-history
keep_reports: ${{ inputs.keep-reports-history }}
github_repo: balances_test_result
github_repo_owner: novasamatech

- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ inputs.token }}
publish_branch: gh-pages
publish_dir: allure-history
external_repository: novasamatech/balances_test_result
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ import io.novafoundation.nova.runtime.di.RuntimeApi
import io.novafoundation.nova.runtime.di.RuntimeComponent
import io.novafoundation.nova.runtime.ext.accountIdOf
import io.novafoundation.nova.runtime.ext.utilityAsset
import io.novafoundation.nova.runtime.extrinsic.signer.NovaSigner
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain
import io.novafoundation.nova.runtime.multiNetwork.connection.ChainConnection
import io.novasama.substrate_sdk_android.encrypt.MultiChainEncryption
import io.novasama.substrate_sdk_android.encrypt.SignatureWrapper
import io.novasama.substrate_sdk_android.encrypt.junction.BIP32JunctionDecoder
import io.novasama.substrate_sdk_android.encrypt.keypair.Keypair
import io.novasama.substrate_sdk_android.encrypt.keypair.ethereum.EthereumKeypairFactory
import io.novasama.substrate_sdk_android.encrypt.seed.ethereum.EthereumSeedFactory
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.KeyPairSigner
import io.novasama.substrate_sdk_android.runtime.AccountId
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.SignedExtrinsic
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.SignedRaw
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.SignerPayloadExtrinsic
import io.novasama.substrate_sdk_android.runtime.extrinsic.signer.SignerPayloadRaw
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import java.math.BigDecimal

private val TEST_MNEMONIC = "second wire page void maid example hazard record assist funny flower enough"


@RunWith(AndroidJUnit4::class)
class MoonbaseSendIntagrationTest {

Expand All @@ -50,13 +55,37 @@ class MoonbaseSendIntagrationTest {
return EthereumKeypairFactory.generate(seed, junctions)
}

private inner class TestSigner(
private val testPayload: (SignerPayloadExtrinsic) -> Unit
) : NovaSigner {

val accountId = ByteArray(32) { 1 }

override suspend fun signExtrinsic(payloadExtrinsic: SignerPayloadExtrinsic): SignedExtrinsic {
testPayload(payloadExtrinsic)
return SignedExtrinsic(payloadExtrinsic, SignatureWrapper.Sr25519(ByteArray(64)))
}

override suspend fun signRaw(payload: SignerPayloadRaw): SignedRaw {
error("Not implemented")
}

override suspend fun signerAccountId(chain: Chain): AccountId {
return accountId
}

override suspend fun modifyPayload(payloadExtrinsic: SignerPayloadExtrinsic): SignerPayloadExtrinsic {
return payloadExtrinsic
}
}

@Test
fun testTransfer() = runBlocking {
externalRequirementFlow.emit(ChainConnection.ExternalRequirement.ALLOWED)
val chain = chainRegistry.getChain("91bc6e169807aaa54802737e1c504b2577d4fafedd5a02c10293b1cd60e39527")

val accountId = chain.accountIdOf("0x0c7485f4AA235347BDE0168A59f6c73C7A42ff2C")
val signer = KeyPairSigner(keypair, MultiChainEncryption.Ethereum)
val signer = TestSigner {_ ->}

val extrinsic = extrinsicBuilderFactory.create(chain, signer, accountId)
.nativeTransfer(accountId, chain.utilityAsset.planksFromAmount(BigDecimal.ONE), keepAlive = true)
Expand Down
Loading

0 comments on commit 54961eb

Please sign in to comment.