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 26, 2023
1 parent 4ff0fc4 commit 9764b5e
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 2 deletions.
14 changes: 13 additions & 1 deletion .github/actions/setup-solana/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ runs:
path: |
~/.cache/solana/
~/.local/share/solana/
key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}
key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}-${{ env.SOLANG_VERSION }}
- uses: nick-fields/retry@v2
if: steps.cache-solana.outputs.cache-hit != 'true'
with:
Expand All @@ -20,6 +20,18 @@ 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 -sSL -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
chmod 755 /home/runner/.local/share/solana/install/active_release/bin/solang
- 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
6 changes: 6 additions & 0 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
solana_cli_version:
required: true
type: string
solang_version:
required: true
type: string
node_version:
required: true
type: string
Expand All @@ -21,6 +24,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 +449,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
3 changes: 2 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"cpi-returns",
"multiple-suites",
"multiple-suites-run-single",
"bpf-upgradeable-state"
"bpf-upgradeable-state",
"solang"
],
"dependencies": {
"@project-serum/common": "^0.0.1-beta.3",
Expand Down
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
13 changes: 13 additions & 0 deletions tests/solang/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[features]
seeds = false
skip-lint = false

[programs.localnet]
flipper = "F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC"

[provider]
cluster = "Localnet"
wallet = "~/.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 @@
{
"name": "solang",
"version": "0.28.0",
"license": "(MIT OR Apache-2.0)",
"homepage": "https://github.com/coral-xyz/anchor#readme",
"bugs": {
"url": "https://github.com/coral-xyz/anchor/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/coral-xyz/anchor.git"
},
"engines": {
"node": ">=11"
},
"scripts": {
"test": "anchor run test-with-build"
}
}
22 changes: 22 additions & 0 deletions tests/solang/solidity/flipper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
contract flipper {
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;
}
}
43 changes: 43 additions & 0 deletions tests/solang/tests/solang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Flipper } from "../target/types/flipper";

describe("flipper", () => {
// 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.Flipper as Program<Flipper>;

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,
"skipLibCheck": true
}
}

0 comments on commit 9764b5e

Please sign in to comment.