Skip to content

Commit

Permalink
Merge pull request zingolabs#528 from juanky201271/dev_summaries_simp…
Browse files Browse the repository at this point in the history
…le_test_added

Summaries test added
  • Loading branch information
Oscar-Pepper authored Sep 29, 2023
2 parents b865eb3 + 4628423 commit 82ee6b3
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 36 deletions.
41 changes: 24 additions & 17 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
name: Build test artifacts
runs-on: macos-12
steps:
- name: Set envs for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
run: echo "REPO-OWNER=zingolabs" >> $GITHUB_ENV

- name: Checkout repository
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -56,7 +60,7 @@ jobs:
needs: build-test-artifacts
strategy:
matrix:
partition: [1, 2, 3]
partition: [1, 2, 3, 4]
steps:
- name: Set envs for zingolib CI
if: ${{ contains(github.repository, 'zingolib') }}
Expand Down Expand Up @@ -91,6 +95,24 @@ jobs:
echo "AVD-ARCH=x86" >> $GITHUB_ENV
echo "NEXTEST-ABI=arm32" >> $GITHUB_ENV
- name: Install docker
run: |
brew install docker
colima start
- name: Pull regchest docker image
run: docker pull zingodevops/regchest:004

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Cargo cache
uses: Swatinem/rust-cache@v2

- name: Native rust cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -134,21 +156,6 @@ jobs:
max_attempts: 3
command: ./scripts/integration_tests.sh -a ${{ env.AVD-ARCH }} -s

- name: Install docker
run: |
brew install docker
colima start
- name: Pull regchest docker image
run: docker pull zingodevops/regchest:003

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Download archive
uses: actions/download-artifact@v3
with:
Expand All @@ -160,7 +167,7 @@ jobs:
run: |
cargo nextest run ${{ env.NEXTEST-ABI }} --verbose --profile ci \
--archive-file nextest-archive.tar.zst \
--partition count:${{ matrix.partition}}/3
--partition count:${{ matrix.partition}}/4
- name: Upload test reports
if: ${{ ! cancelled() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.junit.Test
import org.junit.experimental.categories.Category
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.google.common.collect.Range

object Seeds {
const val ABANDON = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"
Expand Down Expand Up @@ -77,6 +78,18 @@ data class Send (
val memo : String?
)

data class Summaries (
val block_height : Long,
val datetime : Long,
val txid : String,
val price : String?,
val amount : Long,
val to_address : String?,
val memos : List<String>?,
val kind : String,
val pool : String?
)

@Category(OfflineTest::class)
class ExecuteAddressesFromSeed {
@Test
Expand Down Expand Up @@ -244,14 +257,18 @@ class ExecuteSendFromOrchard {
System.out.println("\nBalance pre-send:")
System.out.println(balanceJson)
val balancePreSend: Balance = mapper.readValue(balanceJson)
assertThat(balancePreSend.spendable_orchard_balance).isEqualTo(1000000)
assertThat(balancePreSend.verified_orchard_balance).isEqualTo(780000)
assertThat(balancePreSend.spendable_orchard_balance).isEqualTo(780000)
assertThat(balancePreSend.verified_sapling_balance).isEqualTo(100000)
assertThat(balancePreSend.spendable_sapling_balance).isEqualTo(100000)
assertThat(balancePreSend.transparent_balance).isEqualTo(0)

var addressesJson = RustFFI.execute("addresses", "")
System.out.println("\nAddresses:")
System.out.println(addressesJson)
val addresses: List<Addresses> = mapper.readValue(addressesJson)

// 100_000 + 10_000fee -> 110_000 / 780_000 - 110_000 -> 670_000
val send = Send(addresses[0].receivers.transparent, 100000, null)

var txidJson = RustFFI.execute("send", mapper.writeValueAsString(listOf(send)))
Expand All @@ -270,7 +287,75 @@ class ExecuteSendFromOrchard {
System.out.println("\nBalance post-send:")
System.out.println(balanceJson)
val balancePostSend: Balance = mapper.readValue(balanceJson)
// because the balance is unverified for a while.
assertThat(balancePostSend.orchard_balance).isEqualTo(670000)
//assertThat(balancePostSend.verified_orchard_balance).isEqualTo(670000)
//assertThat(balancePostSend.spendable_orchard_balance).isEqualTo(670000)
assertThat(balancePostSend.verified_sapling_balance).isEqualTo(100000)
assertThat(balancePostSend.spendable_sapling_balance).isEqualTo(100000)
assertThat(balancePostSend.transparent_balance).isEqualTo(100000)
}
}

class ExecuteSummariesFromSeed {
@Test
fun executeSummariesFromSeed() {
val mapper = jacksonObjectMapper()

val server = "http://10.0.2.2:20000"
val chainhint = "regtest"
val seed = Seeds.HOSPITAL
val birthday = "1"
val datadir = MainApplication.getAppContext()!!.filesDir.path
val monitorMempool = "false"

var initFromSeedJson = RustFFI.initfromseed(server, seed, birthday, datadir, chainhint, monitorMempool)
System.out.println("\nInit from seed:")
System.out.println(initFromSeedJson)
val initFromSeed: InitFromSeed = mapper.readValue(initFromSeedJson)
assertThat(initFromSeed.seed).isEqualTo(Seeds.HOSPITAL)
assertThat(initFromSeed.birthday).isEqualTo(1)

var syncJson = RustFFI.execute("sync", "")
System.out.println("\nSync:")
System.out.println(syncJson)

var summariesJson = RustFFI.execute("summaries", "")
System.out.println("\nSummaries:")
System.out.println(summariesJson)
val summaries: List<Summaries> = mapper.readValue(summariesJson)
// the summaries can have 4 or 5 items for 3 different txs
// 1. Received - 1_000_000 - orchard (1 item)
// 2. Sent - 110_000 - uregtest1zkuzfv5m3... (2 items: Sent & fee)
// 3. SendToSelf - 10_000 - Two possible results:
// 3.1. only one item with the fee.
// 3.2. two items: SendToSelf = 0 & fee
assertThat(summaries.size).isIn(Range.closed(4, 5))
// first item have to be a `Received`
assertThat(summaries[0].kind).isEqualTo("Received")
assertThat(summaries[0].pool).isEqualTo("Orchard")
assertThat(summaries[0].amount).isEqualTo(1000000)
// second item have to be a `Sent`
assertThat(summaries[1].kind).isEqualTo("Sent")
assertThat(summaries[1].to_address).isEqualTo("uregtest1zkuzfv5m3yhv2j4fmvq5rjurkxenxyq8r7h4daun2zkznrjaa8ra8asgdm8wwgwjvlwwrxx7347r8w0ee6dqyw4rufw4wg9djwcr6frzkezmdw6dud3wsm99eany5r8wgsctlxquu009nzd6hsme2tcsk0v3sgjvxa70er7h27z5epr67p5q767s2z5gt88paru56mxpm6pwz0cu35m")
assertThat(summaries[1].amount).isEqualTo(100000)
// third item have to be a `fee` from the last `Sent` with the same txid
assertThat(summaries[2].kind).isEqualTo("Fee")
assertThat(summaries[2].txid).isEqualTo(summaries[1].txid)
assertThat(summaries[2].amount).isEqualTo(10000)
if (summaries.size == 4) {
// fourth item have to be a `fee` from a `SendToSelf` tx
assertThat(summaries[3].kind).isEqualTo("Fee")
assertThat(summaries[3].amount).isEqualTo(10000)
} else {
// fouth item have to be a `SendToSelf`
assertThat(summaries[3].kind).isEqualTo("SendToSelf")
assertThat(summaries[3].amount).isEqualTo(0)
// fifth item have to be a `fee` from the last `SendToSelf` with the same txid
assertThat(summaries[4].kind).isEqualTo("Fee")
assertThat(summaries[4].txid).isEqualTo(summaries[3].txid)
assertThat(summaries[4].amount).isEqualTo(10000)
}

}
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "21.4.7075529" //"25.2.9519653"
kotlinVersion = '1.8.0'
kotlinVersion = '1.6.21'
}
repositories {
google()
Expand Down
22 changes: 11 additions & 11 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 49 additions & 6 deletions rust/android/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ async fn offline_testsuite(abi: &str) {

async fn execute_sync_from_seed(abi: &str) {
#[cfg(not(feature = "regchest"))]
let (regtest_manager, _child_process_handler) = scenarios::unfunded_mobileclient().await;
#[cfg(not(feature = "regchest"))]
regtest_manager
.generate_n_blocks(9)
.expect("Failed to generate blocks.");
let (_regtest_manager, _child_process_handler) =
scenarios::funded_orchard_with_3_txs_mobileclient(1_000_000).await;
#[cfg(feature = "regchest")]
let docker = match regchest_utils::launch(UNIX_SOCKET).await {
Ok(d) => d,
Expand All @@ -50,7 +47,7 @@ async fn execute_sync_from_seed(abi: &str) {
async fn execute_send_from_orchard(abi: &str) {
#[cfg(not(feature = "regchest"))]
let (_regtest_manager, _child_process_handler) =
scenarios::funded_orchard_mobileclient(1_000_000).await;
scenarios::funded_orchard_with_3_txs_mobileclient(1_000_000).await;
#[cfg(feature = "regchest")]
let docker = match regchest_utils::launch(UNIX_SOCKET).await {
Ok(d) => d,
Expand All @@ -73,6 +70,32 @@ async fn execute_send_from_orchard(abi: &str) {
assert_eq!(exit_code, 0);
}

async fn execute_summaries_from_seed(abi: &str) {
#[cfg(not(feature = "regchest"))]
let (_regtest_manager, _child_process_handler) =
scenarios::funded_orchard_with_3_txs_mobileclient(1_000_000).await;
#[cfg(feature = "regchest")]
let docker = match regchest_utils::launch(UNIX_SOCKET).await {
Ok(d) => d,
Err(e) => panic!("Failed to launch regchest docker container: {:?}", e),
};

let (exit_code, output, error) =
zingomobile_utils::android_integration_test(abi, "ExecuteSummariesFromSeed");

#[cfg(feature = "regchest")]
match regchest_utils::close(&docker).await {
Ok(_) => (),
Err(e) => panic!("Failed to close regchest docker container: {:?}", e),
}

println!("Exit Code: {}", exit_code);
println!("Output: {}", output);
println!("Error: {}", error);

assert_eq!(exit_code, 0);
}

mod x86 {
const ABI: &str = "x86";

Expand All @@ -90,6 +113,11 @@ mod x86 {
async fn execute_send_from_orchard() {
super::execute_send_from_orchard(ABI).await;
}

#[tokio::test]
async fn execute_summaries_from_seed() {
super::execute_summaries_from_seed(ABI).await;
}
}

mod x86_64 {
Expand All @@ -109,6 +137,11 @@ mod x86_64 {
async fn execute_send_from_orchard() {
super::execute_send_from_orchard(ABI).await;
}

#[tokio::test]
async fn execute_summaries_from_seed() {
super::execute_summaries_from_seed(ABI).await;
}
}

mod arm32 {
Expand All @@ -128,6 +161,11 @@ mod arm32 {
async fn execute_send_from_orchard() {
super::execute_send_from_orchard(ABI).await;
}

#[tokio::test]
async fn execute_summaries_from_seed() {
super::execute_summaries_from_seed(ABI).await;
}
}

mod arm64 {
Expand All @@ -147,4 +185,9 @@ mod arm64 {
async fn execute_send_from_orchard() {
super::execute_send_from_orchard(ABI).await;
}

#[tokio::test]
async fn execute_summaries_from_seed() {
super::execute_summaries_from_seed(ABI).await;
}
}

0 comments on commit 82ee6b3

Please sign in to comment.