Skip to content

Commit

Permalink
Add simple solang test
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyoung committed Sep 25, 2023
1 parent 5f07fd5 commit d25c8fe
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/actions/setup-solana/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ runs:
retry_on: error
shell: bash
command: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
- uses: nick-fields/retry@v2
if: steps.cache-solana.outputs.cache-hit != 'true'
with:
retry_wait_seconds: 300
timeout_minutes: 2
max_attempts: 10
retry_on: error
shell: bash
command:
curl -o /home/runner/.local/share/solana/install/active_release/bin/solang https://github.com/hyperledger/solang/releases/download/v${{ env.SOLANG_VERSION }}/solang-linux-x86-64
- run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- run: solana-keygen new --no-bip39-passphrase
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/no-caching-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
with:
cache: false
solana_cli_version: 1.16.0
solang_version: 0.3.2
node_version: 17.0.1
cargo_profile: release
anchor_binary_name: anchor-binary-no-caching
3 changes: 3 additions & 0 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
env:
CACHE: inputs.cache
SOLANA_CLI_VERSION: ${{ inputs.solana_cli_version }}
SOLANG_VERSION: ${{ inputs.solang_version }}
NODE_VERSION: ${{ inputs.node_version }}
CARGO_PROFILE: ${{ inputs.cargo_profile }}
ANCHOR_BINARY_NAME: ${{ inputs.anchor_binary_name }}
Expand Down Expand Up @@ -445,6 +446,8 @@ jobs:
path: tests/bench
- cmd: cd tests/idl && ./test.sh
path: tests/idl
- cmd: cd tests/solang && anchor test
path: tests/solang
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
with:
cache: true
solana_cli_version: 1.16.0
solang_version: 0.3.2
node_version: 17.0.1
cargo_profile: debug
anchor_binary_name: anchor-binary
8 changes: 8 additions & 0 deletions tests/solang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
.yarn
8 changes: 8 additions & 0 deletions tests/solang/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
node_modules
dist
build
test-ledger
16 changes: 16 additions & 0 deletions tests/solang/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[features]
seeds = false
skip-lint = false

[programs.localnet]
solang = "F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "Localnet"
wallet = "/home/sean/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
12 changes: 12 additions & 0 deletions tests/solang/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);

// Add your deploy script here.
};
19 changes: 19 additions & 0 deletions tests/solang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.28.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
}
}
22 changes: 22 additions & 0 deletions tests/solang/solidity/solang.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
contract solang {
bool private value = true;

@payer(payer)
constructor() {
print("Hello, World!");
}

/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
function flip() public {
value = !value;
}

/// Simply returns the current value of our `bool`.
function get() public view returns (bool) {
return value;
}
}
37 changes: 37 additions & 0 deletions tests/solang/tests/solang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Solang } from "../target/types/solang";

describe("solang", () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

const dataAccount = anchor.web3.Keypair.generate();
const wallet = provider.wallet;

const program = anchor.workspace.Solang as Program<Solang>;

it("Is initialized!", async () => {
// Add your test here.
const tx = await program.methods.new()
.accounts({ dataAccount: dataAccount.publicKey })
.signers([dataAccount]).rpc();
console.log("Your transaction signature", tx);

const val1 = await program.methods.get()
.accounts({ dataAccount: dataAccount.publicKey })
.view();

console.log("state", val1);

await program.methods.flip()
.accounts({ dataAccount: dataAccount.publicKey })
.rpc();

const val2 = await program.methods.get()
.accounts({ dataAccount: dataAccount.publicKey })
.view();

console.log("state", val2); });
});
11 changes: 11 additions & 0 deletions tests/solang/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
}

0 comments on commit d25c8fe

Please sign in to comment.