Skip to content

Commit

Permalink
Update Cadence tests to latest API features and include them in `unit…
Browse files Browse the repository at this point in the history
…-tests` workflow (#22)

* Update Cadence tests to latest API features and include them in unit-tests workflow

* Run Cadence tests in separate job

* Add Cadence tests for scoped providers

* Replace JS testing with Cadence testing framework

* Update unit testing workflow to use setup-go@v4 action

Co-authored-by: Bjarte S. Karlsen <bjarte@bjartek.org>

---------

Co-authored-by: Bjarte S. Karlsen <bjarte@bjartek.org>
  • Loading branch information
m-Peter and bjartek authored Nov 6, 2023
1 parent 19935dd commit c10ce02
Show file tree
Hide file tree
Showing 30 changed files with 792 additions and 556 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ on:
branches: [main]
jobs:
tests:
name: Flow CLI Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ^16
- name: Install flow cli
run: sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"
- name: Start flow emulator
run: nohup flow emulator &
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test -- --runInBand
- uses: actions/checkout@v3
with:
submodules: "true"
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.5.0
- name: Run tests
run: flow test --cover --covercode="contracts" test/*_test.cdc
10 changes: 7 additions & 3 deletions cadence/contracts/AddressUtils.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StringUtils from "StringUtils"
import "StringUtils"

pub contract AddressUtils {

Expand Down Expand Up @@ -94,7 +94,7 @@ pub contract AddressUtils {
}

pub fun getNetworkFromAddress(_ input: AnyStruct): String? {
for network in ["MAINNET", "TESTNET", "EMULATOR"]{
for network in ["MAINNET", "TESTNET", "EMULATOR"] {
if self.isValidAddress(input, forNetwork: network){
return network
}
Expand All @@ -103,7 +103,11 @@ pub contract AddressUtils {
}

pub fun currentNetwork(): String {
return self.getNetworkFromAddress(self.account.address)!
if let network = self.getNetworkFromAddress(self.account.address) {
return network!
}

panic("unknown network!")
}

}
4 changes: 2 additions & 2 deletions cadence/contracts/ScopedFTProviders.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FungibleToken from "./FungibleToken.cdc"
import StringUtils from "./StringUtils.cdc"
import "FungibleToken"
import "StringUtils"

// ScopedFTProviders
//
Expand Down
4 changes: 2 additions & 2 deletions cadence/contracts/ScopedNFTProviders.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NonFungibleToken from "./NonFungibleToken.cdc"
import StringUtils from "./StringUtils.cdc"
import "NonFungibleToken"
import "StringUtils"

// ScopedNFTProviders
//
Expand Down
2 changes: 1 addition & 1 deletion cadence/contracts/StringUtils.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ArrayUtils from "ArrayUtils"
import "ArrayUtils"

pub contract StringUtils {

Expand Down
11 changes: 0 additions & 11 deletions cadence/scripts/address_utils_get_current_network.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/address_utils_get_network_from_address.cdc

This file was deleted.

26 changes: 0 additions & 26 deletions cadence/scripts/address_utils_is_valid_address.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/address_utils_parse_address.cdc

This file was deleted.

36 changes: 0 additions & 36 deletions cadence/scripts/address_utils_parse_uint64.cdc

This file was deleted.

18 changes: 0 additions & 18 deletions cadence/scripts/address_utils_without_prefix.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/string_utils_contains.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/string_utils_count.cdc

This file was deleted.

14 changes: 0 additions & 14 deletions cadence/scripts/string_utils_explode.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/string_utils_format.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/string_utils_has_prefix.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/string_utils_has_suffix.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/string_utils_index.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/string_utils_join.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/string_utils_replace_all.cdc

This file was deleted.

14 changes: 0 additions & 14 deletions cadence/scripts/string_utils_split.cdc

This file was deleted.

17 changes: 0 additions & 17 deletions cadence/scripts/string_utils_substring_until.cdc

This file was deleted.

11 changes: 0 additions & 11 deletions cadence/scripts/string_utils_trim.cdc

This file was deleted.

Loading

0 comments on commit c10ce02

Please sign in to comment.