Skip to content

Commit f1b5633

Browse files
committed
Add anchor-test to initialise and build a sample app
this can catch a lot of issues when it comes to anchor behaviour that is not caught by just compiling anchor
1 parent 4746896 commit f1b5633

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ jobs:
4040
- name: Test Anchor CLI
4141
run: |
4242
nix run .#anchor-cli -- --version
43+
44+
- name: Test Anchor Program
45+
run: |
46+
nix build .#anchor-test -L --impure --option sandbox false

anchor-test.nix

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
11
{
22
stdenv,
33
anchor-cli,
4+
solana-cli,
5+
solana-rust,
46
runCommand,
7+
nodejs,
8+
yarn,
9+
cacert
510
}:
611
let
7-
src = runCommand "anchor-test-src"
8-
{
9-
nativeBuildInputs = [ anchor-cli ];
10-
}
11-
''
12-
mkdir -p $out
13-
cd $out
14-
anchor init example -j --no-install --no-git --test-template rust
15-
mv example/.* example/* .
16-
rm -rf example
17-
'';
12+
src =
13+
runCommand "anchor-test-src"
14+
{
15+
nativeBuildInputs = [
16+
anchor-cli
17+
nodejs
18+
yarn
19+
];
20+
}
21+
''
22+
mkdir -p $out
23+
cd $out
24+
export HOME=$(mktemp -d)
25+
RUST_LOG=trace anchor init example --javascript --no-install --no-git --package-manager yarn
26+
mv example/.* example/* .
27+
rm -rf example
28+
'';
1829
in
1930
stdenv.mkDerivation {
31+
# Disable sandboxing
32+
# this is for CI live test check and we want to make sure
33+
# anchor init and build work when ran by a user
34+
__noChroot = true;
2035
pname = "anchor-test";
2136
inherit src;
2237
version = "1.0.0";
2338

2439
doCheck = false;
2540

26-
nativeBuildInputs = [ anchor-cli ];
41+
nativeBuildInputs = [
42+
anchor-cli
43+
solana-cli
44+
nodejs
45+
yarn
46+
solana-rust
47+
cacert
48+
];
2749

2850
buildPhase = ''
51+
export HOME=$(mktemp -d)
52+
yarn install
53+
solana-keygen new --no-bip39-passphrase
2954
anchor build
3055
anchor test
3156
'';
57+
58+
# Write an output so its cached
3259
installPhase = ''
3360
echo ok > $out
3461
'';
3562

3663
meta = {
37-
description = "Anchor build testing";
64+
description = "Anchor build testing of a new project initialised";
3865
};
3966
}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
crane = crane.mkLib pkgs;
5555
};
5656
anchor-test = pkgs.callPackage ./anchor-test.nix {
57-
inherit anchor-cli;
57+
inherit anchor-cli solana-cli solana-rust;
5858
};
5959
in
6060
{

0 commit comments

Comments
 (0)