fedimint / fedimint-clientd

MIT License
13 stars 14 forks source link

fix::> Added testify/assert || added basic tests for client #13

Closed PsychoPunkSage closed 4 months ago

PsychoPunkSage commented 5 months ago

Added basic test codes for fedimint-go

PsychoPunkSage commented 5 months ago

hi @Kodylow I saw there was some changes made in the fedimint-go/client.go file. So I updated my test cases accordingly. But I noticed some missing fn like SwitchGateway, AwaitPay. Is there any reason for their absence or they will be added later? (Was busy with lab tests so wasn't able to focus much this side )

Kodylow commented 5 months ago

There's no more active gateway on the fedimint-clientd side so that active gateway logic switched to wrapper side logic. Await pay was a redundant method so removed

PsychoPunkSage commented 5 months ago

Ohk, got it

I have posted an issue related to fedimint-clientd in discord channel. Can you please tell how should I proceed?

Kodylow commented 5 months ago

Can you link to that? And this doesn't match the requests pattern I'm using in the typescript, and it doesn't run locally when I just tried, is this ready for review?

PsychoPunkSage commented 5 months ago

Can you link to that? And this doesn't match the requests pattern I'm using in the typescript, and it doesn't run locally when I just tried, is this ready for review?

No I'm not able to test it currently as I'm facing problem in running clientd... Its is not ready yet. As soon as the error get sorted with clientd I will make the changes to properly test it... won't take mush time in making changes I suppose

Discord Discussion Link :: nix-direnv issue is solved but clientd issue still exist

PsychoPunkSage commented 5 months ago

My .env currently look like this...

FEDIMINT_CLIENTD_INVITE_CODE = 'fed1...'
FEDIMINT_CLIENTD_DB_PATH = '/absolute/path/to/fm_db_dir'
FEDIMINT_CLIENTD_PASSWORD = 'some-secure-password-that-becomes-the-bearer-token'
FEDIMINT_CLIENTD_ADDR = '127.0.0.1:3333'

Can you tell the valid value for all the fields.. especially FEDIMINT_CLIENTD_INVITE_CODE and FEDIMINT_CLIENTD_DB_PATH?

I'm getting these errors..

$ sudo nix develop -i $ just dev

image

$ nix develop -i $ just dev

Screenshot from 2024-03-29 13-55-50

Kodylow commented 5 months ago

I just updated the example.env to have useful mutinynet defaults, you can use those

PsychoPunkSage commented 5 months ago

I just updated the example.env to have useful mutinynet defaults, you can use those

Yes it is working now.... I will try to complete this test suite within few days (actually our semester is ending so I am involved in lots of tests)

image

PsychoPunkSage commented 5 months ago

I want to ask that fm_db has 2 folders multimint.db and 15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3.db... what are these?? and what are they used for??

Kodylow commented 5 months ago

The MultiMint.db is a master DB, each sub DB is a specific client DB for a federation, the name of the DB is the federationId

PsychoPunkSage commented 5 months ago

Can you link to that? And this doesn't match the requests pattern I'm using in the typescript, and it doesn't run locally when I just tried, is this ready for review?

hi So I have implemented TEST for ADMIN METHODS inside func TestFedimintGo also edited justfile.local.just

Altough, I face a small issue: On running just test-go-pps (after nix develop -i) I'm getting errors...

cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go
warning: GOPATH set to GOROOT () has no effect
go: module cache not found: neither GOMODCACHE nor GOPATH is set
error: Recipe `test-go-pps` failed on line 14 with exit code 1

I think the GOPATH is not exposed to nix shell, Currently sorting it.. Can you test whether test is working or not??

Concern

I have little concern regarding newKeyPair()... I have implemented it in a different way.. (Can you look at it?)

Kodylow commented 5 months ago

will review today, yeah you need to add go into the flake.nix

PsychoPunkSage commented 5 months ago

Hi Kodylow. I have implemented all the tests. Please review it. Thank You

Kodylow commented 5 months ago

(nix:nix-shell-env) Kodys-MacBook-Pro-2:fedimint-clientd kody$ just test-go-pps cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go

command-line-arguments [command-line-arguments.test]

pkg/fedimint/client_test.go:81:33: undefined: FedimintClient pkg/fedimint/client_test.go:96:21: undefined: FedimintClient pkg/fedimint/client_test.go:98:9: undefined: NewFedimintClient FAIL command-line-arguments [build failed] FAIL error: Recipe test-go-pps failed on line 14 with exit code 1

PsychoPunkSage commented 5 months ago

hi @Kodylow I have updated the file as you have told me in the discord.. Please have a look at it

PsychoPunkSage commented 5 months ago

Hi, I have a little issue in my hand... regarding Golang support inside nix-shell I tried many methods but they didn't method..

Currently I changed my shell.nix to this

# save this as shell.nix
{ pkgs ? import <nixpkgs> {}}:

pkgs.mkShell {
+ buildInputs = with pkgs; [ go ];
  packages = [ pkgs.hello ];
}

.bashrc

......
# Nix-pkg-manager
- nix = {
-   package = pkgs.nix;
-   settings.experimental-features = [ "nix-command" "flakes" ];
- };
......

After I did this nix develop -i > nix-shell ./shell.nix > just test-go Error::>

cd wrappers/fedimint-go && go run -mod=mod cmd/main.go
warning: GOPATH set to GOROOT () has no effect
go: module cache not found: neither GOMODCACHE nor GOPATH is set
error: Recipe `test-go` failed on line 11 with exit code 1

I don't much about what is going wrong

Kodylow commented 5 months ago

you have to change it in the flake.nix, not the shell.nix

PsychoPunkSage commented 5 months ago

Hi @Kodylow I tried to use Golang inside nix shell like this

flake_nix ```nix { description = "A fedimint client daemon for server side applications to hold, use, and manage Bitcoin"; inputs = { nixpkgs = { url = "github:nixos/nixpkgs/nixos-23.11"; }; flakebox = { url = "github:rustshop/flakebox"; inputs.nixpkgs.follows = "nixpkgs"; }; fedimint = { url = "github:fedimint/fedimint?rev=c32bbe8ed8d95ae420b5879e92dda6ce48f5c914"; }; flake-utils.url = "github:numtide/flake-utils"; go = inputs.nixpkgs.go }; outputs = { self, nixpkgs, flakebox, flake-utils, fedimint, go }: flake-utils.lib.eachDefaultSystem (system: let nixpkgs = fedimint.inputs.nixpkgs; pkgs = import nixpkgs { inherit system; overlays = fedimint.overlays.fedimint; }; lib = pkgs.lib; fmLib = fedimint.lib.${system}; flakeboxLib = flakebox.lib.${system} { }; rustSrc = flakeboxLib.filterSubPaths { root = builtins.path { name = "fedimint-clientd"; path = ./.; }; paths = [ "Cargo.toml" "Cargo.lock" ".cargo" "src" ]; }; toolchainArgs = { extraRustFlags = "--cfg tokio_unstable"; } // lib.optionalAttrs pkgs.stdenv.isDarwin { # on Darwin newest stdenv doesn't seem to work # linking rocksdb stdenv = pkgs.clang11Stdenv; }; # all standard toolchains provided by flakebox toolchainsStd = flakeboxLib.mkStdFenixToolchains toolchainArgs; toolchainsNative = (pkgs.lib.getAttrs [ "default" ] toolchainsStd); toolchainNative = flakeboxLib.mkFenixMultiToolchain { toolchains = toolchainsNative; }; commonArgs = { buildInputs = [ pkgs.openssl ] ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ]; nativeBuildInputs = [ pkgs.pkg-config ]; }; outputs = (flakeboxLib.craneMultiBuild { toolchains = toolchainsStd; }) (craneLib': let craneLib = (craneLib'.overrideArgs { pname = "flexbox-multibuild"; src = rustSrc; }).overrideArgs commonArgs; in rec { workspaceDeps = craneLib.buildWorkspaceDepsOnly { }; workspaceBuild = craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; }; fedimint-clientd = craneLib.buildPackageGroup { pname = "fedimint-clientd"; packages = [ "fedimint-clientd" ]; mainProgram = "fedimint-clientd"; }; }); in { legacyPackages = outputs; packages = { default = outputs.fedimint-clientd; }; devShells = fmLib.devShells // { default = fmLib.devShells.default.overrideAttrs (prev: { nativeBuildInputs = [ pkgs.mprocs fedimint.packages.${system}.devimint fedimint.packages.${system}.gateway-pkgs fedimint.packages.${system}.fedimint-pkgs go ] ++ prev.nativeBuildInputs; }); }; }); } ```

But it is not working. I have very little idea about nix + very AIs also misleading me.... Can you please provide me the flakes.nix setup that you are using along with some nix materials so that I can handle such basic things?

PsychoPunkSage commented 5 months ago

Plus is the test working?? I think I mirrored everything

Kodylow commented 5 months ago

Go is definitely working, just rebase this PR I updated the flake for it yesterday for you. I just tested on my computer and replit in the flake so no idea why you're getting a flake error if you're rebased.

Running your pps tests throws that a bunch of stuff is undefined, running my test.go it errors at discover version but I haven't finished updating all of them yet. I'm almost done updating all the python stuff, between python and typescript that should be enough to mirror the go stuff

PsychoPunkSage commented 5 months ago

pps one can be scrapped... as I have updated the tests in main.go file. So, if the test is running after executing just test-go then this PR is all good to be merged...

Ok if Python is updated then I will use it to mirror go_tests

PsychoPunkSage commented 5 months ago

I checked python tests... there was nothing much to add. Everything was updated. So you can take a look at it.. I have one question... fedimint-go has ClaimPubkeyReceive and CreateInvoiceForPubkey functions. But these functions are missing in both fedimint-py and fedimint-ts. Not sure whether to remove it or not

Kodylow commented 5 months ago

I removed those on purpose, those 2 shouldn't be used, you should only use the tweak methods

The go tests are still failing on the discoverVersion for me, I finished updating all the python stuff yesterday and merged it

PsychoPunkSage commented 5 months ago

Still getting an error image

Steps I am following:

  1. nix develop -i
  2. just dev: Let it compile. fedimint-clientd: up | user: down | ngrok: down
  3. in another terminal:: nix develop -i > just test-go and its failing with above error..
PsychoPunkSage commented 5 months ago

The go tests are still failing on the discoverVersion for me, I finished updating all the python stuff yesterday and merged it

Got it whats the issue. I will change it..

PsychoPunkSage commented 5 months ago

Hello.. I have made required changes and I think now discover_version should work. (Earlier threshold var was optional, I made it compulsory and passed 1 as threshold var.)

Kodylow commented 5 months ago

Getting there, some of the outputs don't look deserialized and I get a segfault on join:

Method: /v2/admin/discover-version
jsonBody:  {"threshold":1}
Input:  1
Output:  &map[15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3:map[version:map[core:map[maj
or:0 minor:1] modules:map[0:map[major:0 minor:0] 1:map[major:0 minor:0] 2:map[major:0 minor:0]]]]]
--------------------
--------------------
Method: /v2/admin/federation-ids
Input:  <nil>
Output:  {[15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3]}
--------------------
--------------------
Method: /v2/admin/info
Input:  <nil>
Output:  &{  map[] 0 0 {map[]}}
--------------------
--------------------
Method: /v2/admin/join
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1025477e4]
PsychoPunkSage commented 5 months ago

Still getting an error image

Steps I am following:

  1. nix develop -i
  2. just dev: Let it compile. fedimint-clientd: up | user: down | ngrok: down
  3. in another terminal:: nix develop -i > just test-go and its failing with above error..

This thing is giving me pain due to which I'm not able to test anything... Can you please see what possibly is going wrong. I searched everything but couldn't find any working soln :(

RESOLVED IT NO WORRIES :)

PsychoPunkSage commented 5 months ago

@Kodylow Added serialize and deserialize lines to each output lines

Are u working on something cause i'm getting this new error on running just dev image

Already have version > 1.74.0

rustc --version
rustc 1.75.0 (82e1608df 2023-12-21)
Kodylow commented 5 months ago

Make sure you rerun nix develop, was updating the flake

PsychoPunkSage commented 5 months ago

Yeah did that. Still getting that error. Maybe there is something that got missed while updating. No issues.

PsychoPunkSage commented 5 months ago

Hi @Kodylow I want some clarification on something

I found that some of the tests in my test_scripts are failing with some random HTTP errors like 500, 400, 402 etc.. Does this mean that tests are running fine but there is issue with connection??

Thank You

Kodylow commented 5 months ago

Okay I'm still getting errors whenever I run these. For those errors you have to figure out individually why they're throwing, some are because the method signatures are wrong, some are maybe because you're running the tests outside just dev so the client isn't running, some aren't converting the types properly, they depend on the specific tests. Here's a branch with me trying to fix some of them, got through to /invoice but looks like the go types for gateway are off https://github.com/fedimint/fedimint-clientd/tree/kody-go-test

PsychoPunkSage commented 5 months ago

Yeah, I will go through them and sort the issues

PsychoPunkSage commented 5 months ago

Hi Kodylow Got some updates...

ADMIN FUNCTIONS are all working

LIGHTNING METHODS

  • list-gateways giving 405 error; I am using all the commands after just dev. I don'r know why its not working, it should work... is there any issue of limited access (u used ActiveFederationId as a parameter BUT I think I doesn't take any parameters)
  • CreateInvoice Error 422
    Error calling INVOICE:  HTTP error! status: 422, message: Failed to deserialize the JSON body into the target type: gatewayId: malformed public key at line 1 column 163

for gateway-id i crosschecked it many times. it is implemented in the same way as in fedimint-py and fedimint-ts...

MINT METHODS

  • Spend Error 500
    500, message: Something went wrong: Insufficient balance: requested 3000 msat but only 0 msat available

I think I need some msat with me to test this function (which I don't have). How can I get those msat?

ONCHAIN METHODS

  • they are giving 404 error -_-

If you will be doing some sessions in general channel please let me know i can join it to speedrun things

PsychoPunkSage commented 5 months ago

Also there are some disparity between FedimintClient.py and client.go... What should I do?? Should I update FedimintClient.py or client.go??

PsychoPunkSage commented 4 months ago

Hi @Kodylow :eyes: :eyes:

Hi Kodylow Got some updates...

ADMIN FUNCTIONS are all working

LIGHTNING METHODS

  • list-gateways giving 405 error; I am using all the commands after just dev. I don'r know why its not working, it should work... is there any issue of limited access (u used ActiveFederationId as a parameter BUT I think I doesn't take any parameters)
  • CreateInvoice Error 422
Error calling INVOICE:  HTTP error! status: 422, message: Failed to deserialize the JSON body into the target type: gatewayId: malformed public key at line 1 column 163

for gateway-id i crosschecked it many times. it is implemented in the same way as in fedimint-py and fedimint-ts...

MINT METHODS

  • Spend Error 500
500, message: Something went wrong: Insufficient balance: requested 3000 msat but only 0 msat available

I think I need some msat with me to test this function (which I don't have). How can I get those msat?

ONCHAIN METHODS

  • they are giving 404 error -_-

If you will be doing some sessions in general channel please let me know i can join it to speedrun things

PsychoPunkSage commented 4 months ago

Also Kody I have gone through SoB Project Idea.... I was thinking to start working on it asap (given only 20 days are left and I have endsems exams too)...

I am interested in both the task Not sure which one to move forward with... Can you give some insight in this regard??

But before going any further I think I should wrap up this PR first.... (Its is open for quite some time) Thank you

Kodylow commented 4 months ago

@PsychoPunkSage For that first error you're not passing a gatewayId in, you have to do that now for all the lightning methods.

For the second error it's using mutinynet sats for the tests and hitting against the Fedi Testnet federation, you can get some sats from this faucet https://faucet.mutinynet.com

Happy to help with any SoB things you need just send me a discord DM

PsychoPunkSage commented 4 months ago

For getting mutinynet sats. Do I need to set up a wallet or something?? Or should I use FEDIMINT_CLIENTD_INVITE_CODE from .env file to get msats in it?

PsychoPunkSage commented 4 months ago

@PsychoPunkSage For that first error you're not passing a gatewayId in, you have to do that now for all the lightning methods.

Ok Sorted this error.... But listGateways fn shouldn't take any parameter right? As internally It is calling get method which doesn't require gatewayIds to get infos... But still it is giving 405 errors...

PsychoPunkSage commented 4 months ago

@Kodylow Is nix shell working?? Cause I'm getting error on just dev

image

Its telling that i dont have pkg-config (/usr/bin/pkg-config) but I have... Plus i have also added it to PATH var

NOT Showing up in echo $PATH ```bash $ echo $PATH | tr ':' '\n' /home/psychopunk_sage/dev/terminal-setup/ohmyposh /home/psychopunk_sage/.pyenv/shims /home/psychopunk_sage/.pyenv/bin /home/psychopunk_sage/.nix-profile/bin /nix/var/nix/profiles/default/bin /home/psychopunk_sage/.cargo/bin /home/psychopunk_sage/.nix-profile/bin /nix/var/nix/profiles/default/bin /home/psychopunk_sage/.nix-profile/bin /nix/var/nix/profiles/default/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /snap/bin /snap/bin /usr/local/go/bin ```
Kodylow commented 4 months ago

Yes the nix flake is working for me on both mac and linux.

Listgateways needs to take a federationId and should be a post request.

The default federation_invite_code in .env is for the mutinynet federation fedi set up, you can just use the fedimint-clientd client to create an invoice, pay it from the faucet, and you'll have the sats

Kodylow commented 4 months ago

nix develop is definitely working on master. You just generate a lightning invoice from the fedimint-clientd on the default .env's federation id (that's the fedi mutinynet federation) then pay the lightning invoice from the mutinynet faucet

listGateways requires you to pass in a federationId and should be a post

PsychoPunkSage commented 4 months ago

Listgateways needs to take a federationId and should be a post request.

Ohk, Then in that case I have to make a listGatewayRequest to send request via postWithFederationId..... right? And since listGatewayRequest is not given I have to make one inside modules/ln.go.... But how should I frame the request? What should be fields of it?? Is is written somewhere?

Kodylow commented 4 months ago

yup, you can see the requests in the rust side or use the typescript / python impls for reference. I'm going to try to land this today, about to test it and see if I can just get the last little issues

Kodylow commented 4 months ago

okay got everything working on here, I can't commit to your branch. You can mirror those changes or you can pull it down and force push it up

https://github.com/fedimint/fedimint-clientd/tree/psychopunk-working

Kodylow commented 4 months ago

would also be nice if you could squash your changes down please haha

PsychoPunkSage commented 4 months ago

Hi Yeah this will the first thing I will do in morning. :)

PsychoPunkSage commented 4 months ago

Hi @Kodylow

would also be nice if you could squash your changes down please haha

I have pushed the required changes that you asked me to do... please have a look