Open Killpit opened 1 year ago
Thanks! Can you share exactly the code you're trying to compile please?
Python code
`# calculator
from seahorse.prelude import *
declare_id('Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS')
class Calculator(Account): owner: Pubkey display: i64
class Operation(Enum): ADD = 0 SUB = 1 MUL = 2 DIV = 3
@instruction def init_calculator(owner: Signer, calculator: Empty[Calculator]): calculator = calculator.init(payer = owner, seeds = ['Calculator', owner]) calculator.owner = owner.key()
@instruction def reset_calculator(owner: Signer, calculator: Calculator): print(owner.key(), 'is resetting a calculator', calculator.key())
assert owner.key() == calculator.owner, 'This is not your calculator!'
calculator.display = 0
@instruction def do_operation(owner: Signer, calculator: Calculator, op: Operation, num: i64): assert owner.key() == calculator.owner, 'This is not your calculator!'
if op == Operation.ADD: calculator.display += num elif op == Operation.SUB: calculator.display -= num elif op == Operation.MUL: calculator.display *= num elif op == Operation.DIV: calculator.display //= num `
It builds
`import * as anchor from "@project-serum/anchor"; import { BN, Program, web3 } from "@project-serum/anchor"; import { Calculator } from "../target/types/calculator"; const assert = require("assert");
describe("calculator", () => { const provider = anchor.AnchorProvider.env() anchor.setProvider(provider);
const program = anchor.workspace.Calculator as Program
const owner = provider.wallet.publicKey const calculator = web3.PublicKey.findProgramAddressSync( [Buffer.from('Calculator'), owner.toBuffer()], program.programId )[0]
it("Initializes a calculator", async () => { const tx = await program.methods.initCalculator().accounts({ owner, calculator }).rpc(); });
it('Does arithmetic operations', async () => { const add2 = await program.methods .doOperation({ add: true }, new BN(2)) .accounts({ owner, calculator }) .instruction()
const mul3 = await program.methods
.doOperation({ mul: true}, new BN(3))
.accounts({ owner, calculator })
.instruction()
const sub1 = await program.methods
.doOperation({ sub: true }, new BN(1))
.accounts({ owner, calculator })
.instruction()
const tx = new web3.Transaction()
tx.add(add2, mul3, sub1)
await provider.sendAndConfirm(tx)
const calculatorAccount = await program.account.calculator.fetch(calculator)
assert.ok(calculatorAccount.display.toNumber() === 5)
});
it('Prevents fraudulent transactions', async () => { let hackerman = new web3.Keypair()
let shouldFail = await program.methods
.resetCalculator()
.accounts({
owner: hackerman.publicKey,
calculator,
})
.instruction()
let tx = new web3.Transaction( tx.add(shouldFail) await provider .sendAndConfirm(tx, [hackerman]) .then(() => assert.ok(false)) .catch(console.log) ) }) }); `
@Killpit as with my comment here, please use triple backtick code blocks
''' import * as anchor from "@project-serum/anchor"; import { BN, Program, web3 } from "@project-serum/anchor"; import { Calculator } from "../target/types/calculator"; const assert = require("assert");
describe("calculator", () => { const provider = anchor.AnchorProvider.env() anchor.setProvider(provider);
const program = anchor.workspace.Calculator as Program
const owner = provider.wallet.publicKey const calculator = web3.PublicKey.findProgramAddressSync( [Buffer.from('Calculator'), owner.toBuffer()], program.programId )[0]
it("Initializes a calculator", async () => { const tx = await program.methods.initCalculator().accounts({ owner, calculator }).rpc(); });
it('Does arithmetic operations', async () => { const add2 = await program.methods .doOperation({ add: true }, new BN(2)) .accounts({ owner, calculator }) .instruction()
const mul3 = await program.methods
.doOperation({ mul: true}, new BN(3))
.accounts({ owner, calculator })
.instruction()
const sub1 = await program.methods
.doOperation({ sub: true }, new BN(1))
.accounts({ owner, calculator })
.instruction()
const tx = new web3.Transaction()
tx.add(add2, mul3, sub1)
await provider.sendAndConfirm(tx)
const calculatorAccount = await program.account.calculator.fetch(calculator)
assert.ok(calculatorAccount.display.toNumber() === 5)
});
it('Prevents fraudulent transactions', async () => { let hackerman = new web3.Keypair()
let shouldFail = await program.methods
.resetCalculator()
.accounts({
owner: hackerman.publicKey,
calculator,
})
.instruction()
let tx = new web3.Transaction( tx.add(shouldFail) await provider .sendAndConfirm(tx, [hackerman]) .then(() => assert.ok(false)) .catch(console.log) ) }) }); '''
seahorse build ✗ Compiling calculator... (note: if this is your first time building, it might take a few minutes) Error: anchor build -p calculator failed:
This is most likely a bug in the Seahorse compiler!
If you want to help the project, you can report this:
Thanks!
Compiling syn v1.0.109 Compiling toml_edit v0.19.4 Compiling regex v1.7.1 Compiling proc-macro-crate v1.3.1 Compiling proc-macro2-diagnostics v0.9.1 Compiling borsh-derive-internal v0.9.3 Compiling borsh-schema-derive-internal v0.9.3 error: could not compile
borsh-schema-derive-internal
Caused by: could not execute process
rustc --crate-name borsh_schema_derive_internal --edition=2018 /Users/atatekeli/.cargo/registry/src/github.com-1ecc6299db9ec823/borsh-schema-derive-internal-0.9.3/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C overflow-checks=on -C metadata=5c156f6b369bdd2c -C extra-filename=-5c156f6b369bdd2c --out-dir /Users/atatekeli/calculator/target/release/deps -L dependency=/Users/atatekeli/calculator/target/release/deps --extern proc_macro2=/Users/atatekeli/calculator/target/release/deps/libproc_macro2-e71e4eb7661bf272.rmeta --extern quote=/Users/atatekeli/calculator/target/release/deps/libquote-4f5955c0bc56a4bf.rmeta --extern syn=/Users/atatekeli/calculator/target/release/deps/libsyn-8d87a2ff23a45535.rmeta --cap-lints allow
(never executed)Caused by: Resource temporarily unavailable (os error 35) warning: build failed, waiting for other jobs to finish... error: could not compile
borsh-derive-internal
Caused by: could not execute process
rustc --crate-name borsh_derive_internal --edition=2018 /Users/atatekeli/.cargo/registry/src/github.com-1ecc6299db9ec823/borsh-derive-internal-0.9.3/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C overflow-checks=on -C metadata=ff4d752cb39cb352 -C extra-filename=-ff4d752cb39cb352 --out-dir /Users/atatekeli/calculator/target/release/deps -L dependency=/Users/atatekeli/calculator/target/release/deps --extern proc_macro2=/Users/atatekeli/calculator/target/release/deps/libproc_macro2-e71e4eb7661bf272.rmeta --extern quote=/Users/atatekeli/calculator/target/release/deps/libquote-4f5955c0bc56a4bf.rmeta --extern syn=/Users/atatekeli/calculator/target/release/deps/libsyn-8d87a2ff23a45535.rmeta --cap-lints allow
(never executed)Caused by: Resource temporarily unavailable (os error 35)
AtaTekeli:calculator atatekeli$
I just created a simple calculator program according to tutorial and never added anything other than generic seahorse code that being created after seahorse init command