Skip to content

Commit

Permalink
- Upgrade anchor 0.29.0
Browse files Browse the repository at this point in the history
- Update Solana cli CI version 1.14.17 -> 1.17.18
- Update node CI version 18 -> 22
- Add rust toolchain to fix CI runner to rust 1.74.1
- Enable overflow-checks as required by anchor 0.30.0
- Error on alias types - they are broken in anchor 0.29.0 anyway
  • Loading branch information
elliotkennedy committed Dec 8, 2024
1 parent e41f6cf commit 546e4d7
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
branches:
- master
env:
SOLANA_CLI_VERSION: 1.14.17
NODE_VERSION: 18
SOLANA_CLI_VERSION: 1.17.18
NODE_VERSION: 22

jobs:
example-program-tests:
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.74.1"
13 changes: 12 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function jsonInterfaceName(typeName: string) {
export function isComplexType(
ty: IdlType
): ty is
| IdlTypeDefined
| IdlTypeArray
| IdlTypeVec
| IdlTypeOption
Expand Down Expand Up @@ -125,6 +124,9 @@ export function tsTypeFromIdl(
const name = kindInterfaceName(ty.defined)
return `${definedTypesPrefix}${name}`
}
case "alias": {
throw new Error("alias layout support not implemented")
}
}
}
if (isComplexType(ty) && "array" in ty) {
Expand Down Expand Up @@ -306,6 +308,9 @@ export function fieldToEncodable(
case "enum": {
return `${valPrefix}${ty.name}.toEncodable()`
}
case "alias": {
throw new Error("alias layout support not implemented")
}
}
}
if (isComplexType(ty.type) && "array" in ty.type) {
Expand Down Expand Up @@ -402,6 +407,8 @@ export function fieldFromDecoded(
case "struct":
case "enum":
return `${definedTypesPrefix}${ty.type.defined}.fromDecoded(${valPrefix}${ty.name})`
case "alias":
throw new Error("alias layout support not implemented")
default: {
unreachable(filtered[0].type)
throw new Error("Unreachable.")
Expand Down Expand Up @@ -469,6 +476,8 @@ export function structFieldInitializer(
case "enum":
filtered[0].type.kind
return `${prefix}${field.name}`
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(filtered[0].type)
return
Expand Down Expand Up @@ -618,6 +627,8 @@ export function fieldToJSON(idl: Idl, ty: IdlField, valPrefix = ""): string {
case "struct":
case "enum":
return `${valPrefix}${ty.name}.toJSON()`
case "alias":
throw new Error("alias layout support not implemented")
default: {
unreachable(filtered[0].type)
throw new Error("Unreachable.")
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function genIndexFile(
.join(" | "),
})
return
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(ty.type)
}
Expand All @@ -109,6 +111,8 @@ function genTypeFiles(
genEnum(idl, src, ty.name, ty.type.variants)
return
}
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(ty.type)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/example-program-gen/exp/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as FooEnum from "./FooEnum"

export { BarStruct } from "./BarStruct"
export type { BarStructFields, BarStructJSON } from "./BarStruct"
export { FooStruct } from "./FooStruct"
export type { FooStructFields, FooStructJSON } from "./FooStruct"
export { FooEnum }

/** Enum type */
Expand All @@ -23,3 +21,6 @@ export type FooEnumJSON =
| FooEnum.OptionStructJSON
| FooEnum.VecStructJSON
| FooEnum.NoFieldsJSON

export { FooStruct } from "./FooStruct"
export type { FooStructFields, FooStructJSON } from "./FooStruct"
96 changes: 48 additions & 48 deletions tests/example-program-gen/idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,54 +450,6 @@
]
}
},
{
"name": "FooStruct",
"type": {
"kind": "struct",
"fields": [
{
"name": "field1",
"type": "u8"
},
{
"name": "field2",
"type": "u16"
},
{
"name": "nested",
"type": {
"defined": "BarStruct"
}
},
{
"name": "vecNested",
"type": {
"vec": {
"defined": "BarStruct"
}
}
},
{
"name": "optionNested",
"type": {
"option": {
"defined": "BarStruct"
}
}
},
{
"name": "enumField",
"type": {
"defined": "FooEnum"
}
},
{
"name": "pubkeyField",
"type": "publicKey"
}
]
}
},
{
"name": "FooEnum",
"docs": [
Expand Down Expand Up @@ -579,6 +531,54 @@
}
]
}
},
{
"name": "FooStruct",
"type": {
"kind": "struct",
"fields": [
{
"name": "field1",
"type": "u8"
},
{
"name": "field2",
"type": "u16"
},
{
"name": "nested",
"type": {
"defined": "BarStruct"
}
},
{
"name": "vecNested",
"type": {
"vec": {
"defined": "BarStruct"
}
}
},
{
"name": "optionNested",
"type": {
"option": {
"defined": "BarStruct"
}
}
},
{
"name": "enumField",
"type": {
"defined": "FooEnum"
}
},
{
"name": "pubkeyField",
"type": "publicKey"
}
]
}
}
],
"errors": [
Expand Down
5 changes: 3 additions & 2 deletions tests/example-program/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/example-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
members = [
"programs/*"
]

[profile.release]
overflow-checks = true
1 change: 1 addition & 0 deletions tests/example-program/programs/example-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "^0.29.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ it("tx error", async () => {
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 invoke [1]",
"Program log: Instruction: CauseError",
"Program log: AnchorError thrown in programs/example-program/src/lib.rs:90. Error Code: SomeError. Error Number: 6000. Error Message: Example error..",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 consumed 2293 of 200000 compute units",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 consumed 2304 of 200000 compute units",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 failed: custom program error: 0x1770",
])

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"sourceMap": true,
"moduleResolution": "node",
"noEmit": true,
"isolatedModules": true
"isolatedModules": true,
"skipLibCheck": true
},
"include": ["src", "tests", "examples"],
}

0 comments on commit 546e4d7

Please sign in to comment.