Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Program and tests written for minting token #1

Closed
wants to merge 4 commits into from

Conversation

sammanadh
Copy link
Collaborator

Just wrote a simple program and test case for minting token. THIS IS A DRAFT PR, NOT FOR MERGING. didn't see a draft option while creating a pr. I guess it has to be enabled or something.

@sammanadh sammanadh requested a review from nathanleclaire July 12, 2022 14:45
@nathanleclaire
Copy link
Contributor

Yea I'm sure there's some fancy Github workflow option but we usually just throw [WIP] or [nomerge] in the PR title.

@nathanleclaire
Copy link
Contributor

is this what you're hitting in the tests?

yarn run v1.22.15
$ /Users/nathanleclaire/karma/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'

TypeError: Module "file:///Users/nathanleclaire/karma/tsconfig.json" needs an import assertion of type "json"
    at new NodeError (node:internal/errors:372:5)
    at validateAssertions (node:internal/modules/esm/assert:82:15)
    at defaultLoad (node:internal/modules/esm/load:24:3)
    at ESMLoader.load (node:internal/modules/esm/loader:407:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:326:22)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:345:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:304:34)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at formattedImport (/Users/nathanleclaire/karma/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at Object.exports.requireOrImport (/Users/nathanleclaire/karma/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
    at Object.exports.loadFilesAsync (/Users/nathanleclaire/karma/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
    at singleRun (/Users/nathanleclaire/karma/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/Users/nathanleclaire/karma/node_modules/mocha/lib/cli/run.js:374:5)

@nathanleclaire
Copy link
Contributor

#2 looks like it should fix the above, but I get a new and exciting error now --

Error: Error loading workspace IDL for karma
    at /Users/nathanleclaire/karma/node_modules/@project-serum/anchor/src/workspace.ts:102:13
    at Array.forEach (<anonymous>)
    at attachWorkspaceOverride (/Users/nathanleclaire/karma/node_modules/@project-serum/anchor/src/workspace.ts:91:31)
    at Object.get (/Users/nathanleclaire/karma/node_modules/@project-serum/anchor/src/workspace.ts:72:9)
    at Suite.<anonymous> (/Users/nathanleclaire/karma/tests/karmaToken.ts:19:38)
    at Object.create (/Users/nathanleclaire/karma/node_modules/mocha/lib/interfaces/common.js:148:19)

looking into it...

@nathanleclaire
Copy link
Contributor

nathanleclaire commented Jul 13, 2022

ah ok so for this other error i think you need these changes --

diff --git a/Anchor.toml b/Anchor.toml
index 9bf3ac1..9e62d44 100644
--- a/Anchor.toml
+++ b/Anchor.toml
@@ -2,7 +2,7 @@
 seeds = false
 
 [programs.localnet]
-karma = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
+karma_token = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 
 [registry]
 url = "https://anchor.projectserum.com"
diff --git a/Cargo.lock b/Cargo.lock
index 34440dd..9a83057 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -649,7 +649,7 @@ dependencies = [
 ]
 
 [[package]]
-name = "karma"
+name = "karma_token"
 version = "0.1.0"
 dependencies = [
  "anchor-lang",
diff --git a/package.json b/package.json
index 20973c1..0e288ed 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
         "chai": "^4.3.4",
         "mocha": "^9.0.3",
         "prettier": "^2.6.2",
-        "ts-mocha": "^8.0.0",
+        "ts-mocha": "^10.0.0",
         "typescript": "^4.3.5"
     }
 }
diff --git a/programs/karma/Cargo.toml b/programs/karma/Cargo.toml
index 44fda3f..ece1df0 100644
--- a/programs/karma/Cargo.toml
+++ b/programs/karma/Cargo.toml
@@ -1,12 +1,12 @@
 [package]
-name = "karma"
+name = "karma_token"
 version = "0.1.0"
 description = "Created with Anchor"
 edition = "2021"
 
 [lib]
 crate-type = ["cdylib", "lib"]
-name = "karma"
+name = "karma_token"

probably anchor is confused about the rename karma -> karma_token . Anchor autogenerates a lot of stuff based on those names so you have to watch them closely

@nathanleclaire
Copy link
Contributor

with that, first passing test, good times

Screen Shot 2022-07-12 at 6 04 25 PM

@sammanadh
Copy link
Collaborator Author

@nathanleclaire did the test pass without you making any changes to the karmaTokan.ts test file itself?

@nathanleclaire
Copy link
Contributor

@sammanadh Yea. Are you hitting a new issue?

@sammanadh
Copy link
Collaborator Author

@nathanleclaire Yeah.

  1) karma token
       Minting a new token.:
     Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist
      at Connection.sendEncodedTransaction (node_modules/@solana/web3.js/src/connection.ts:4480:13)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Connection.sendRawTransaction (node_modules/@solana/web3.js/src/connection.ts:4439:20)
      at sendAndConfirmRawTransaction (node_modules/@project-serum/anchor/src/provider.ts:284:21)
      at AnchorProvider.sendAndConfirm (node_modules/@project-serum/anchor/src/provider.ts:144:14)
      at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:29:16)

Its on line 17 in karmaToken.ts test file.

    await program.methods.mintToken().accounts({
        mint: mintKeyPair.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
        tokenAccount: associatedTokenAccount,
        authority: walletPubKey,
    }).rpc();

Currently using localnet. Have deployed the program successfully there. Don't know why I am still getting this error. Planning to work on devnet once and see if the error persists there as well.

@sammanadh
Copy link
Collaborator Author

@nathanleclaire Finally, tests are passing successfully. Somehow, I had messed up copying the program id. Stupid mistake.

@sammanadh sammanadh closed this Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants