Skip to content

Commit

Permalink
add formatter to contracts (#832)
Browse files Browse the repository at this point in the history
* add formatter to CI + makefile

* fix formatting
  • Loading branch information
aalu1418 authored Aug 26, 2024
1 parent 02a8105 commit 51842d5
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 43 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ jobs:
with:
path: contracts/target
key: ${{ runner.os }}-v2-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: format contracts + artifacts
run: |
yarn install --frozen-lockfile
cd ../ # back to root
make format-contracts
echo "run 'make format-contracts' if this fails"
git diff --stat --exit-code
- name: cargo check
env:
Expand All @@ -117,6 +125,3 @@ jobs:
cd /repo/contracts &&\
cargo check &&\
cargo clippy -- -D warnings"
# - run: cargo check
# - run: cargo clippy -- -D warnings
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ upgrade-e2e-solana-image:
.PHONY: update-e2e-core-deps
upgrade-e2e-core-deps:
cd ./integration-tests && ../scripts/update-e2e.sh

.PHONY: format-contracts
format-contracts:
cd ./contracts && cargo fmt && go fmt ./... && yarn format
2 changes: 1 addition & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ Install `https://github.com/gagliardetto/anchor-go`
Current version: [v0.2.3](https://github.com/gagliardetto/anchor-go/tree/v0.2.3)

```bash
./scripts/anchor-go-gen.sh
./scripts/anchor-go-gen.sh
```
7 changes: 6 additions & 1 deletion contracts/artifacts/localnet/access_controller-keypair.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[88,83,177,128,199,1,114,89,250,247,46,18,107,162,26,125,19,233,229,58,251,38,17,221,10,202,45,185,250,64,243,39,24,4,109,145,171,35,102,148,236,12,238,74,222,116,201,243,109,158,98,122,7,32,21,13,158,190,72,124,157,104,243,12]
[
88, 83, 177, 128, 199, 1, 114, 89, 250, 247, 46, 18, 107, 162, 26, 125, 19,
233, 229, 58, 251, 38, 17, 221, 10, 202, 45, 185, 250, 64, 243, 39, 24, 4,
109, 145, 171, 35, 102, 148, 236, 12, 238, 74, 222, 116, 201, 243, 109, 158,
98, 122, 7, 32, 21, 13, 158, 190, 72, 124, 157, 104, 243, 12
]
7 changes: 6 additions & 1 deletion contracts/artifacts/localnet/ocr_2-keypair.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[9,218,36,113,218,176,180,196,27,75,171,187,105,81,84,58,52,79,85,169,125,13,0,102,214,246,82,252,133,222,160,252,193,218,154,28,253,34,136,185,53,68,165,141,248,188,247,143,17,100,91,130,75,49,212,131,37,18,151,175,201,153,131,185]
[
9, 218, 36, 113, 218, 176, 180, 196, 27, 75, 171, 187, 105, 81, 84, 58, 52,
79, 85, 169, 125, 13, 0, 102, 214, 246, 82, 252, 133, 222, 160, 252, 193, 218,
154, 28, 253, 34, 136, 185, 53, 68, 165, 141, 248, 188, 247, 143, 17, 100, 91,
130, 75, 49, 212, 131, 37, 18, 151, 175, 201, 153, 131, 185
]
7 changes: 6 additions & 1 deletion contracts/artifacts/localnet/store-keypair.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[189,212,127,119,126,129,229,12,201,157,100,223,53,182,209,144,82,137,39,42,199,212,116,181,52,188,127,6,123,161,148,74,129,253,6,129,56,138,171,117,217,146,177,54,182,120,125,247,100,54,203,214,204,177,0,83,158,177,77,195,0,245,49,223]
[
189, 212, 127, 119, 126, 129, 229, 12, 201, 157, 100, 223, 53, 182, 209, 144,
82, 137, 39, 42, 199, 212, 116, 181, 52, 188, 127, 6, 123, 161, 148, 74, 129,
253, 6, 129, 56, 138, 171, 117, 217, 146, 177, 54, 182, 120, 125, 247, 100,
54, 203, 214, 204, 177, 0, 83, 158, 177, 77, 195, 0, 245, 49, 223
]
38 changes: 26 additions & 12 deletions contracts/examples/hello-world/tests/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe("hello-world", () => {
const store = anchor.web3.Keypair.generate();
const feed = anchor.web3.Keypair.generate();

let storeIdl = JSON.parse(fs.readFileSync("../../target/idl/store.json", "utf-8"));
let storeIdl = JSON.parse(
fs.readFileSync("../../target/idl/store.json", "utf-8")
);
const storeProgram = new Program(storeIdl, CHAINLINK_PROGRAM_ID, provider);

// Create a feed
Expand All @@ -42,35 +44,47 @@ describe("hello-world", () => {
feed,
header + (liveLength + historicalLength) * transmissionSize
),
]).rpc({ commitment: "confirmed" });
])
.rpc({ commitment: "confirmed" });
console.log("deployed store");

await storeProgram.methods.setWriter(owner.publicKey).accounts({
feed: feed.publicKey,
owner: owner.publicKey,
authority: owner.publicKey,
}).rpc({ commitment: "confirmed" });
await storeProgram.methods
.setWriter(owner.publicKey)
.accounts({
feed: feed.publicKey,
owner: owner.publicKey,
authority: owner.publicKey,
})
.rpc({ commitment: "confirmed" });
console.log("set writer on store");

const scale = new BN(10).pow(new BN(decimals));
// Scale answer to enough decimals
let answer = new BN(1).mul(scale);
let round = { timestamp: new BN(1), answer };

let tx = await storeProgram.methods.submit(round).accounts({
let tx = await storeProgram.methods
.submit(round)
.accounts({
store: store.publicKey,
feed: feed.publicKey,
authority: owner.publicKey,
}).rpc({ commitment: "confirmed" });
})
.rpc({ commitment: "confirmed" });
console.log("value written to store");

// Add your test here.
tx = await program.methods.execute().accounts({
tx = await program.methods
.execute()
.accounts({
chainlinkFeed: feed.publicKey,
chainlinkProgram: CHAINLINK_PROGRAM_ID,
}).rpc({ commitment: "confirmed" });
})
.rpc({ commitment: "confirmed" });
console.log("Your transaction signature", tx);
let t = await provider.connection.getTransaction(tx, { commitment: "confirmed" });
let t = await provider.connection.getTransaction(tx, {
commitment: "confirmed",
});
console.log(t.meta.logMessages);
});
});
48 changes: 24 additions & 24 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"dependencies": {
"@chainlink/solana-sdk": "../ts",
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.50.1 <=1.92.3",
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.37",
"@types/secp256k1": "^4.0.3",
"bn.js": "^5.2.0",
"borsh": "^0.7.0",
"chai": "^4.3.4",
"ethereum-cryptography": "^0.1.3",
"mocha": "^9.0.0",
"prettier": "^2.5.1",
"rpc-websockets": "<=7.10.0",
"secp256k1": "^4.0.2",
"ts-mocha": "^8.0.0",
"typescript": "^4.5.4"
},
"scripts": {
"format": "yarn prettier --write .",
"test": "yarn upgrade @chainlink/solana-sdk && ts-mocha -t 1000000 tests/*.ts"
}
"dependencies": {
"@chainlink/solana-sdk": "../ts",
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.50.1 <=1.92.3",
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.37",
"@types/secp256k1": "^4.0.3",
"bn.js": "^5.2.0",
"borsh": "^0.7.0",
"chai": "^4.3.4",
"ethereum-cryptography": "^0.1.3",
"mocha": "^9.0.0",
"prettier": "^2.5.1",
"rpc-websockets": "<=7.10.0",
"secp256k1": "^4.0.2",
"ts-mocha": "^8.0.0",
"typescript": "^4.5.4"
},
"scripts": {
"format": "yarn prettier --write .",
"test": "yarn upgrade @chainlink/solana-sdk && ts-mocha -t 1000000 tests/*.ts"
}
}

0 comments on commit 51842d5

Please sign in to comment.