From 99adfd1fb26937287a9331848bcd23a339b1efff Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 25 Mar 2024 23:13:12 +0530 Subject: [PATCH 01/23] fix::> Added testify/assert || added basic tests for client --- .direnv/flake-profile | 1 + .direnv/flake-profile-1-link | 1 + wrappers/fedimint-go/go.mod | 5 + wrappers/fedimint-go/go.sum | 9 + .../fedimint-go/pkg/fedimint/client_test.go | 334 ++++++++++++++++++ 5 files changed, 350 insertions(+) create mode 120000 .direnv/flake-profile create mode 120000 .direnv/flake-profile-1-link create mode 100644 wrappers/fedimint-go/pkg/fedimint/client_test.go diff --git a/.direnv/flake-profile b/.direnv/flake-profile new file mode 120000 index 0000000..0c05709 --- /dev/null +++ b/.direnv/flake-profile @@ -0,0 +1 @@ +flake-profile-1-link \ No newline at end of file diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link new file mode 120000 index 0000000..283ea47 --- /dev/null +++ b/.direnv/flake-profile-1-link @@ -0,0 +1 @@ +/nix/store/q61ni6s1mqr37fcp38wyzm5ryn82z26n-nix-shell-env \ No newline at end of file diff --git a/wrappers/fedimint-go/go.mod b/wrappers/fedimint-go/go.mod index 015fe7f..e629b25 100644 --- a/wrappers/fedimint-go/go.mod +++ b/wrappers/fedimint-go/go.mod @@ -2,8 +2,13 @@ module fedimint-go-client go 1.21.3 +require github.com/stretchr/testify v1.9.0 + require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/joho/godotenv v1.5.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/wrappers/fedimint-go/go.sum b/wrappers/fedimint-go/go.sum index ca953b9..17e4630 100644 --- a/wrappers/fedimint-go/go.sum +++ b/wrappers/fedimint-go/go.sum @@ -1,6 +1,15 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go new file mode 100644 index 0000000..35d8a31 --- /dev/null +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -0,0 +1,334 @@ +// Client_tests +package fedimint + +import ( + "fedimint-go-client/pkg/fedimint/types/modules" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func CreateNewFedimintClient() *FedimintClient { + // Define test data + baseURL := "http://localhost:3333" + password := "password" + federationID := "federation123" + + fc := NewFedimintClient(baseURL, password, federationID) + + return fc +} + +func TestNewFedimintClient(t *testing.T) { + fc := CreateNewFedimintClient() + assert.NotNil(t, fc) + + assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") + assert.Equal(t, fc.Password, "password") + assert.Equal(t, fc.FederationId, "federation123") + + assert.Equal(t, fc, fc.Ln.Client) + assert.Equal(t, fc, fc.Wallet.Client) + assert.Equal(t, fc, fc.Mint.Client) +} + +func TestGetActiveFederationId(t *testing.T) { + fc := CreateNewFedimintClient() + + fedId := fc.getActiveFederationId() + assert.Equal(t, fedId, "federation123") +} + +func TestSetActiveFederationId(t *testing.T) { + fc := CreateNewFedimintClient() + new_fedId := "New_federation123" + + fedId_prev := fc.FederationId + fc.setActiveFederationId(new_fedId) + fedId_now := fc.FederationId + assert.Equal(t, fedId_now, "New_federation123") + assert.NotEqual(t, fedId_now, fedId_prev) +} + +//////////// +// Wallet // +//////////// + +func TestCreateDepositAddress(t *testing.T) { + fc := CreateNewFedimintClient() + + depositAddressRequest := modules.DepositAddressRequest{ + Timeout: 3600, + } + + depositResponse, err := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, depositResponse, nil) + assert.Equal(t, depositResponse.OperationID, nil) + assert.Equal(t, depositResponse.Address, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, depositResponse.OperationID, nil) + assert.NotEqual(t, depositResponse.Address, nil) + } + + awaitDepositRequest := modules.AwaitDepositRequest{ + OperationID: depositResponse.OperationID, + } + + _, err = fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + if err != nil { + fmt.Println("Error awaiting deposit: ", err) + return + } +} + +func TestWithdraw(t *testing.T) { + fc := CreateNewFedimintClient() + + withdrawRequest := modules.WithdrawRequest{ + Address: "UNKNOWN", + AmountMsat: "10000", + } + + withdrawResponse, _ := fc.Wallet.withdraw(withdrawRequest, &fc.FederationId) + + assert.NotEqual(t, withdrawResponse, nil) + + // Intentionally make an error (like - wrong FederationId/request) + wrong_fed_id := "12112" + _, err := fc.Wallet.withdraw(withdrawRequest, &wrong_fed_id) + assert.NotEqual(t, err, nil) +} + +func TestAwaitWithdraw(t *testing.T) { + fc := CreateNewFedimintClient() + + depositAddressRequest := modules.DepositAddressRequest{ + Timeout: 3600, + } + depositResponse, _ := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + + awaitDepositRequest := modules.AwaitDepositRequest{ + OperationID: depositResponse.OperationID, + } + + awaitDepositResponse, err := fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, awaitDepositResponse, nil) + assert.Equal(t, awaitDepositResponse.Status, nil) + } else { + assert.Equal(t, err, nil) + // println(awaitDepositResponse.Status) + assert.NotEqual(t, awaitDepositResponse.Status, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Wallet.awaitDeposit(awaitDepositRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +////////// +// mint // +////////// + +// func TestReissue(t *testing.T) { +// fc := CreateNewFedimintClient() + +// oobNotesData := modules.OOBNotes { + +// } +// } + +func TestSpend(t *testing.T) { + fc := CreateNewFedimintClient() + + spendRequest := modules.SpendRequest{ + AmountMsat: 10000, + AllowOverpay: true, + Timeout: 3600, + } + + spendResponse, err := fc.Mint.Spend(spendRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, spendResponse, nil) + assert.Equal(t, spendResponse.Operation, nil) + assert.Equal(t, spendResponse.Notes, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, spendResponse, nil) + assert.NotEqual(t, spendResponse.Operation, nil) + assert.NotEqual(t, spendResponse.Notes, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Mint.Spend(spendRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +// func TestValidate(t *testing.T) { +// fc := CreateNewFedimintClient() + +// } + +//////// +// Ln // +//////// + +func TestCreateInvoice(t *testing.T) { + fc := CreateNewFedimintClient() + + invoiceRequest := modules.LnInvoiceRequest{ + AmountMsat: 10000, + Description: "test", + } + + invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, invoiceResponse, nil) + assert.Equal(t, invoiceResponse.OperationID, nil) + assert.Equal(t, invoiceResponse.Invoice, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, invoiceResponse, nil) + assert.NotEqual(t, invoiceResponse.OperationID, nil) + assert.NotEqual(t, invoiceResponse.Invoice, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.CreateInvoice(invoiceRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestAwaitInvoice(t *testing.T) { + fc := CreateNewFedimintClient() + + awaitInvoiceRequest := modules.AwaitInvoiceRequest{ + OperationID: "TestAwaitInvoice", + } + + infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, infoResponse, nil) + assert.Equal(t, infoResponse.DenominationsMsat, nil) + assert.Equal(t, infoResponse.FederationID, nil) + assert.Equal(t, infoResponse.Meta, nil) + assert.Equal(t, infoResponse.Network, nil) + assert.Equal(t, infoResponse.TotalAmountMsat, nil) + assert.Equal(t, infoResponse.TotalNumNotes, nil) + assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) + } else { + assert.Equal(t, err, nil) + assert.Equal(t, infoResponse.FederationID, fc.FederationId) + assert.NotEqual(t, infoResponse, nil) + assert.NotEqual(t, infoResponse.Meta, nil) + assert.NotEqual(t, infoResponse.Network, nil) + assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) + assert.NotEqual(t, infoResponse.TotalNumNotes, nil) + assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "" + _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestPay(t *testing.T) { + fc := CreateNewFedimintClient() + + lnPayRequest := modules.LnPayRequest{ + Payment_info: "TestPayment", + Finish_in_background: true, + } + + lnPayResponse, err := fc.Ln.Pay(lnPayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, lnPayResponse, nil) + assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.Fee, nil) + assert.Equal(t, lnPayResponse.Payment_type, nil) + assert.Equal(t, lnPayResponse.Pperation_id, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, lnPayResponse, nil) + assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.Fee, nil) + assert.NotEqual(t, lnPayResponse.Payment_type, nil) + assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.Pay(lnPayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestAwaitPay(t *testing.T) { + fc := CreateNewFedimintClient() + + awaitLnPayRequest := modules.AwaitLnPayRequest{ + Operation_id: "TestAwaitLnPay", + } + + lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, lnPayResponse, nil) + assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.Fee, nil) + assert.Equal(t, lnPayResponse.Payment_type, nil) + assert.Equal(t, lnPayResponse.Pperation_id, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, lnPayResponse, nil) + assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.Fee, nil) + assert.NotEqual(t, lnPayResponse.Payment_type, nil) + assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestListGateways(t *testing.T) { + fc := CreateNewFedimintClient() + + gatewaysResponse, err := fc.Ln.ListGateways() + if err != nil { + assert.Equal(t, gatewaysResponse, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, gatewaysResponse, nil) + } +} + +func TestSwitchGateway(t *testing.T) { + fc := CreateNewFedimintClient() + + switchGatewayRequest := modules.SwitchGatewayRequest{ + Gateway_id: "TestGateway1", + } + + gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, gatewayResponse, nil) + assert.Equal(t, gatewayResponse.Active, true) + assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) + } else { + assert.Equal(t, err, nil) + assert.Equal(t, gatewayResponse.Active, true) + assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} From 71b02e9c7e44e791ca91c06be4a66f07cb604041 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 28 Mar 2024 11:41:21 +0530 Subject: [PATCH 02/23] fix:: Updated the test cases according to new changes in the fn, parameter, var names --- .../fedimint-go/pkg/fedimint/client_test.go | 161 +++++++++--------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 35d8a31..9d5d182 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -26,17 +26,17 @@ func TestNewFedimintClient(t *testing.T) { assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") assert.Equal(t, fc.Password, "password") - assert.Equal(t, fc.FederationId, "federation123") + assert.Equal(t, fc.ActiveFederationId, "federation123") assert.Equal(t, fc, fc.Ln.Client) - assert.Equal(t, fc, fc.Wallet.Client) + assert.Equal(t, fc, fc.Onchain.Client) assert.Equal(t, fc, fc.Mint.Client) } func TestGetActiveFederationId(t *testing.T) { fc := CreateNewFedimintClient() - fedId := fc.getActiveFederationId() + fedId := fc.GetActiveFederationId() assert.Equal(t, fedId, "federation123") } @@ -44,40 +44,40 @@ func TestSetActiveFederationId(t *testing.T) { fc := CreateNewFedimintClient() new_fedId := "New_federation123" - fedId_prev := fc.FederationId - fc.setActiveFederationId(new_fedId) - fedId_now := fc.FederationId + fedId_prev := fc.ActiveFederationId + fc.SetActiveFederationId(new_fedId, false) + fedId_now := fc.ActiveFederationId assert.Equal(t, fedId_now, "New_federation123") assert.NotEqual(t, fedId_now, fedId_prev) } //////////// -// Wallet // +// Onchain // //////////// func TestCreateDepositAddress(t *testing.T) { fc := CreateNewFedimintClient() - depositAddressRequest := modules.DepositAddressRequest{ + depositAddressRequest := modules.OnchainDepositAddressRequest{ Timeout: 3600, } - depositResponse, err := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) if err != nil { assert.Equal(t, depositResponse, nil) - assert.Equal(t, depositResponse.OperationID, nil) + assert.Equal(t, depositResponse.OperationId, nil) assert.Equal(t, depositResponse.Address, nil) } else { assert.Equal(t, err, nil) - assert.NotEqual(t, depositResponse.OperationID, nil) + assert.NotEqual(t, depositResponse.OperationId, nil) assert.NotEqual(t, depositResponse.Address, nil) } - awaitDepositRequest := modules.AwaitDepositRequest{ - OperationID: depositResponse.OperationID, + awaitDepositRequest := modules.OnchainAwaitDepositRequest{ + OperationId: depositResponse.OperationId, } - _, err = fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) if err != nil { fmt.Println("Error awaiting deposit: ", err) return @@ -87,34 +87,34 @@ func TestCreateDepositAddress(t *testing.T) { func TestWithdraw(t *testing.T) { fc := CreateNewFedimintClient() - withdrawRequest := modules.WithdrawRequest{ - Address: "UNKNOWN", - AmountMsat: "10000", + withdrawRequest := modules.OnchainWithdrawRequest{ + Address: "UNKNOWN", + AmountSat: 10000, } - withdrawResponse, _ := fc.Wallet.withdraw(withdrawRequest, &fc.FederationId) + withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) assert.NotEqual(t, withdrawResponse, nil) - // Intentionally make an error (like - wrong FederationId/request) + // Intentionally make an error (like - wrong ActiveFederationId/request) wrong_fed_id := "12112" - _, err := fc.Wallet.withdraw(withdrawRequest, &wrong_fed_id) + _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) assert.NotEqual(t, err, nil) } func TestAwaitWithdraw(t *testing.T) { fc := CreateNewFedimintClient() - depositAddressRequest := modules.DepositAddressRequest{ + depositAddressRequest := modules.OnchainDepositAddressRequest{ Timeout: 3600, } - depositResponse, _ := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) - awaitDepositRequest := modules.AwaitDepositRequest{ - OperationID: depositResponse.OperationID, + awaitDepositRequest := modules.OnchainAwaitDepositRequest{ + OperationId: depositResponse.OperationId, } - awaitDepositResponse, err := fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) if err != nil { assert.Equal(t, awaitDepositResponse, nil) assert.Equal(t, awaitDepositResponse.Status, nil) @@ -126,7 +126,7 @@ func TestAwaitWithdraw(t *testing.T) { // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Wallet.awaitDeposit(awaitDepositRequest, &wrong_fed_id) + _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) assert.NotEqual(t, err1, nil) } @@ -145,27 +145,27 @@ func TestAwaitWithdraw(t *testing.T) { func TestSpend(t *testing.T) { fc := CreateNewFedimintClient() - spendRequest := modules.SpendRequest{ + spendRequest := modules.MintSpendRequest{ AmountMsat: 10000, AllowOverpay: true, Timeout: 3600, } - spendResponse, err := fc.Mint.Spend(spendRequest, &fc.FederationId) + spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) if err != nil { assert.Equal(t, spendResponse, nil) - assert.Equal(t, spendResponse.Operation, nil) + assert.Equal(t, spendResponse.OperationId, nil) assert.Equal(t, spendResponse.Notes, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, spendResponse, nil) - assert.NotEqual(t, spendResponse.Operation, nil) + assert.NotEqual(t, spendResponse.OperationId, nil) assert.NotEqual(t, spendResponse.Notes, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Mint.Spend(spendRequest, &wrong_fed_id) + _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) assert.NotEqual(t, err1, nil) } @@ -181,37 +181,40 @@ func TestSpend(t *testing.T) { func TestCreateInvoice(t *testing.T) { fc := CreateNewFedimintClient() + expiryTime := 3600 + GatewayID := "test_GatewayID" invoiceRequest := modules.LnInvoiceRequest{ AmountMsat: 10000, Description: "test", + ExpiryTime: &expiryTime, } - invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest, &fc.FederationId) + invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) if err != nil { assert.Equal(t, invoiceResponse, nil) - assert.Equal(t, invoiceResponse.OperationID, nil) + assert.Equal(t, invoiceResponse.OperationId, nil) assert.Equal(t, invoiceResponse.Invoice, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, invoiceResponse, nil) - assert.NotEqual(t, invoiceResponse.OperationID, nil) + assert.NotEqual(t, invoiceResponse.OperationId, nil) assert.NotEqual(t, invoiceResponse.Invoice, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Ln.CreateInvoice(invoiceRequest, &wrong_fed_id) + _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) assert.NotEqual(t, err1, nil) } func TestAwaitInvoice(t *testing.T) { fc := CreateNewFedimintClient() - awaitInvoiceRequest := modules.AwaitInvoiceRequest{ - OperationID: "TestAwaitInvoice", + awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ + OperationId: "TestAwaitInvoice", } - infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &fc.FederationId) + infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) if err != nil { assert.Equal(t, infoResponse, nil) assert.Equal(t, infoResponse.DenominationsMsat, nil) @@ -223,7 +226,7 @@ func TestAwaitInvoice(t *testing.T) { assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) } else { assert.Equal(t, err, nil) - assert.Equal(t, infoResponse.FederationID, fc.FederationId) + assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) assert.NotEqual(t, infoResponse, nil) assert.NotEqual(t, infoResponse.Meta, nil) assert.NotEqual(t, infoResponse.Network, nil) @@ -234,68 +237,72 @@ func TestAwaitInvoice(t *testing.T) { // intentionally giving wrong parameters wrong_fed_id := "" - _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &wrong_fed_id) + _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) assert.NotEqual(t, err1, nil) } func TestPay(t *testing.T) { fc := CreateNewFedimintClient() + LnurlComment := "test_LnurlComment" + GatewayID := "test_GatewayID" + AmountMsat := uint64(10000) lnPayRequest := modules.LnPayRequest{ - Payment_info: "TestPayment", - Finish_in_background: true, + PaymentInfo: "TestPayment", + AmountMsat: &AmountMsat, + LnurlComment: &LnurlComment, } - lnPayResponse, err := fc.Ln.Pay(lnPayRequest, &fc.FederationId) + lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) if err != nil { assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.ContractId, nil) assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.Payment_type, nil) - assert.Equal(t, lnPayResponse.Pperation_id, nil) + assert.Equal(t, lnPayResponse.PaymentType, nil) + assert.Equal(t, lnPayResponse.PperationId, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.ContractId, nil) assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.Payment_type, nil) - assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + assert.NotEqual(t, lnPayResponse.PaymentType, nil) + assert.NotEqual(t, lnPayResponse.PperationId, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Ln.Pay(lnPayRequest, &wrong_fed_id) + _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) assert.NotEqual(t, err1, nil) } -func TestAwaitPay(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestAwaitPay(t *testing.T) { +// fc := CreateNewFedimintClient() - awaitLnPayRequest := modules.AwaitLnPayRequest{ - Operation_id: "TestAwaitLnPay", - } +// awaitLnPayRequest := modules.AwaitLnPayRequest{ +// OperationId: "TestAwaitLnPay", +// } - lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.FederationId) - if err != nil { - assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.Contract_id, nil) - assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.Payment_type, nil) - assert.Equal(t, lnPayResponse.Pperation_id, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.Contract_id, nil) - assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.Payment_type, nil) - assert.NotEqual(t, lnPayResponse.Pperation_id, nil) - } +// lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, lnPayResponse, nil) +// assert.Equal(t, lnPayResponse.Contract_id, nil) +// assert.Equal(t, lnPayResponse.Fee, nil) +// assert.Equal(t, lnPayResponse.Payment_type, nil) +// assert.Equal(t, lnPayResponse.Pperation_id, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, lnPayResponse, nil) +// assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// assert.NotEqual(t, lnPayResponse.Fee, nil) +// assert.NotEqual(t, lnPayResponse.Payment_type, nil) +// assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } func TestListGateways(t *testing.T) { fc := CreateNewFedimintClient() @@ -313,10 +320,10 @@ func TestSwitchGateway(t *testing.T) { fc := CreateNewFedimintClient() switchGatewayRequest := modules.SwitchGatewayRequest{ - Gateway_id: "TestGateway1", + GatewayId: "TestGateway1", } - gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.FederationId) + gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) if err != nil { assert.Equal(t, gatewayResponse, nil) assert.Equal(t, gatewayResponse.Active, true) From cdebb0d699d4a1bc64770e97f30ba62ed959c201 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 31 Mar 2024 16:29:31 +0530 Subject: [PATCH 03/23] fix::> Added support func to tests and Updated CreateNewFedimintClient() --- .gitignore | 1 + flake.lock | 8 +- shell.nix | 6 ++ wrappers/fedimint-go/go.mod | 5 +- wrappers/fedimint-go/go.sum | 6 ++ .../fedimint-go/pkg/fedimint/client_test.go | 95 +++++++++++++++++-- 6 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index db36602..4f7664f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ fm_client_db .cargo .vscode .DS_Store +fm_db \ No newline at end of file diff --git a/flake.lock b/flake.lock index b61a2c5..ae1e6ab 100644 --- a/flake.lock +++ b/flake.lock @@ -188,17 +188,17 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1710534977, - "narHash": "sha256-RWzV+/NZkV87JnydefwRMwJ9tDkwDCg6m3pCxsVlKeY=", + "lastModified": 1711405975, + "narHash": "sha256-I8uUhpqN5oGDkT+sN4jztzun/wD/mN/CtzCxlV3pdjY=", "owner": "fedimint", "repo": "fedimint", - "rev": "9d552fdf82f4af429165a1fd409615809ada4058", + "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", "type": "github" }, "original": { "owner": "fedimint", "repo": "fedimint", - "rev": "9d552fdf82f4af429165a1fd409615809ada4058", + "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", "type": "github" } }, diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..bfcd84b --- /dev/null +++ b/shell.nix @@ -0,0 +1,6 @@ +# save this as shell.nix +{ pkgs ? import {}}: + +pkgs.mkShell { + packages = [ pkgs.hello ]; +} diff --git a/wrappers/fedimint-go/go.mod b/wrappers/fedimint-go/go.mod index e629b25..c50e3e5 100644 --- a/wrappers/fedimint-go/go.mod +++ b/wrappers/fedimint-go/go.mod @@ -4,10 +4,13 @@ go 1.21.3 require github.com/stretchr/testify v1.9.0 +require github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0 // indirect + require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1 v1.0.4 + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 github.com/joho/godotenv v1.5.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/wrappers/fedimint-go/go.sum b/wrappers/fedimint-go/go.sum index 17e4630..1fce7d4 100644 --- a/wrappers/fedimint-go/go.sum +++ b/wrappers/fedimint-go/go.sum @@ -2,6 +2,12 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1 v1.0.4 h1:0XErmfJBiVbl0NvyclGn4jr+1hIylDf5beFi9W0o7Fc= +github.com/decred/dcrd/dcrec/secp256k1 v1.0.4/go.mod h1:00z7mJdugt+GBAzPN1QrDRGCXxyKUiexEHu6ukxEw3k= +github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0 h1:3GIJYXQDAKpLEFriGFN8SbSffak10UXHGdIcFaMPykY= +github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0/go.mod h1:3s92l0paYkZoIHuj4X93Teg/HB7eGM9x/zokGw+u4mY= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 9d5d182..18d9aba 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -4,20 +4,103 @@ package fedimint import ( "fedimint-go-client/pkg/fedimint/types/modules" "fmt" + "os" "testing" "github.com/stretchr/testify/assert" ) +type KeyPair struct { + PrivateKey string + PublicKey string +} + +func logMethod(method string) { + fmt.Println("--------------------") + fmt.Println("Method:", method) +} + +func logInputAndOutput(input interface{}, output interface{}) { + fmt.Println("Input: ", input) + fmt.Println("Output: ", output) + fmt.Println("--------------------") +} + +// BIG ISSUE // +// func newKeyPair() KeyPair { +// var privateKey *big.Int +// var err error + +// for { +// privateKey, err = rand.Int(rand.Reader, secp256k1.S256().Params().N) +// if err != nil { +// log.Fatal(err) +// } +// if privateKey.Sign() > 0 && privateKey.Cmp(secp256k1.S256().Params().N) < 0 { +// break +// } +// } + +// // publicKey := secp256k1.PublicKey{} +// // secp256k1.S256().SerializePublicKey(publicKey[:], privateKey.Bytes()) + +// publicKey := secp256k1.PublicKey{} +// publicKey1 := secp256k1.PublicKey{ +// x: new(big.Int), +// y: new(big.Int), +// } +// (publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) + +// return KeyPair{ +// PrivateKey: hex.EncodeToString(privateKey.Bytes()), +// PublicKey: hex.EncodeToString(publicKey[:]), +// } +// } + +/* + async function buildTestClient() { + const baseUrl = process.env.FEDIMINT_CLIENTD_BASE_URL || "127.0.0.1:3333"; + const password = process.env.FEDIMINT_CLIENTD_PASSWORD || "password"; + const activeFederationId = + process.env.FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID || + "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"; + const builder = new FedimintClientBuilder(); + builder + .setBaseUrl(baseUrl) + .setPassword(password) + .setActiveFederationId(activeFederationId); + + const client = await builder.build(); + + await client.useDefaultGateway(); + + console.log("Default gateway id: ", client.getActiveGatewayId()); + + return client; + } +*/ func CreateNewFedimintClient() *FedimintClient { // Define test data - baseURL := "http://localhost:3333" - password := "password" - federationID := "federation123" - - fc := NewFedimintClient(baseURL, password, federationID) + baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") + if baseURL == "" { + baseURL = "127.0.0.1:3333" + } + password := os.Getenv("FEDIMINT_CLIENTD_PASSWORD") + if password == "" { + password = "password" + } + activeFederationID := os.Getenv("FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID") + if activeFederationID == "" { + activeFederationID = "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" + } - return fc + done := make(chan *FedimintClient) + go func() { + fc := NewFedimintClient(baseURL, password, activeFederationID) + fc.UseDefaultGateway() + done <- fc + }() + return <-done } func TestNewFedimintClient(t *testing.T) { From 624cdec3ec8c4a3666496946db73ffa6b4c04b3c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 31 Mar 2024 23:47:01 +0530 Subject: [PATCH 04/23] fix::> Added main testing function - TestFedimintGo --- .../fedimint-go/pkg/fedimint/client_test.go | 607 ++++++++++-------- 1 file changed, 338 insertions(+), 269 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 18d9aba..9fa0ccc 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -2,12 +2,13 @@ package fedimint import ( - "fedimint-go-client/pkg/fedimint/types/modules" + "encoding/hex" "fmt" + "log" "os" "testing" - "github.com/stretchr/testify/assert" + "github.com/btcsuite/btcd/btcec/v2" ) type KeyPair struct { @@ -49,36 +50,34 @@ func logInputAndOutput(input interface{}, output interface{}) { // x: new(big.Int), // y: new(big.Int), // } -// (publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) +// //(publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) +// secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) -// return KeyPair{ -// PrivateKey: hex.EncodeToString(privateKey.Bytes()), -// PublicKey: hex.EncodeToString(publicKey[:]), +// return KeyPair{ +// PrivateKey: hex.EncodeToString(privateKey.Bytes()), +// PublicKey: hex.EncodeToString(publicKey[:]), +// } // } -// } - -/* - async function buildTestClient() { - const baseUrl = process.env.FEDIMINT_CLIENTD_BASE_URL || "127.0.0.1:3333"; - const password = process.env.FEDIMINT_CLIENTD_PASSWORD || "password"; - const activeFederationId = - process.env.FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID || - "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"; - const builder = new FedimintClientBuilder(); - builder - .setBaseUrl(baseUrl) - .setPassword(password) - .setActiveFederationId(activeFederationId); - const client = await builder.build(); +func newKeyPair() KeyPair { + privKey, err := btcec.NewPrivateKey() + if err != nil { + log.Fatal("Error generating private key:", err) + } - await client.useDefaultGateway(); + // Get the corresponding public key + pubKey := privKey.PubKey() - console.log("Default gateway id: ", client.getActiveGatewayId()); + // Print the private and public keys + fmt.Printf("Private key: %x\n", privKey.Serialize()) + fmt.Printf("Public key: %x\n", pubKey.SerializeCompressed()) - return client; + return KeyPair{ + PrivateKey: hex.EncodeToString(privKey.Serialize()), + PublicKey: hex.EncodeToString(pubKey.SerializeCompressed()), } -*/ +} + func CreateNewFedimintClient() *FedimintClient { // Define test data baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -103,322 +102,392 @@ func CreateNewFedimintClient() *FedimintClient { return <-done } -func TestNewFedimintClient(t *testing.T) { +func TestFedimintGo(t *testing.T) { fc := CreateNewFedimintClient() - assert.NotNil(t, fc) - - assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") - assert.Equal(t, fc.Password, "password") - assert.Equal(t, fc.ActiveFederationId, "federation123") - - assert.Equal(t, fc, fc.Ln.Client) - assert.Equal(t, fc, fc.Onchain.Client) - assert.Equal(t, fc, fc.Mint.Client) -} - -func TestGetActiveFederationId(t *testing.T) { - fc := CreateNewFedimintClient() - - fedId := fc.GetActiveFederationId() - assert.Equal(t, fedId, "federation123") -} - -func TestSetActiveFederationId(t *testing.T) { - fc := CreateNewFedimintClient() - new_fedId := "New_federation123" - - fedId_prev := fc.ActiveFederationId - fc.SetActiveFederationId(new_fedId, false) - fedId_now := fc.ActiveFederationId - assert.Equal(t, fedId_now, "New_federation123") - assert.NotEqual(t, fedId_now, fedId_prev) -} - -//////////// -// Onchain // -//////////// + keyPair := newKeyPair() + fmt.Printf("Generated Key Pair: ") + fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) + fmt.Printf(" Public Key: %s\n", keyPair.PublicKey) + + /////////////////// + // ADMIN METHODS // + /////////////////// + + // `/v2/admin/config` + logMethod("/v2/admin/config") + data, err := fc.Config() + if err != nil { + fmt.Println("Error calling CONFIG: ", err) + return + } + logInputAndOutput(nil, data) -func TestCreateDepositAddress(t *testing.T) { - fc := CreateNewFedimintClient() + // `/v2/admin/discover-version` + logMethod("/v2/admin/discover-version") + data, err = fc.DiscoverVersion(1) + if err != nil { + fmt.Println("Error calling VERSION: ", err) + return + } + logInputAndOutput(1, data) - depositAddressRequest := modules.OnchainDepositAddressRequest{ - Timeout: 3600, + // `/v2/admin/federation-ids + logMethod("/v2/admin/federation-ids") + federationIds, err := fc.FederationIds() + if err != nil { + fmt.Println("Error calling FEDERATION_IDS: ", err) + return } + logInputAndOutput(nil, federationIds) - depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) + // `/v2/admin/info` + logMethod("/v2/admin/info") + infoData, err := fc.Info() if err != nil { - assert.Equal(t, depositResponse, nil) - assert.Equal(t, depositResponse.OperationId, nil) - assert.Equal(t, depositResponse.Address, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, depositResponse.OperationId, nil) - assert.NotEqual(t, depositResponse.Address, nil) + fmt.Println("Error calling INFO: ", err) + return } + logInputAndOutput(nil, infoData) - awaitDepositRequest := modules.OnchainAwaitDepositRequest{ - OperationId: depositResponse.OperationId, + // `/v2/admin/join` + inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") + if inviteCode == "" { + inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } + logMethod("/v2/admin/join") + joinData, err := fc.Join(inviteCode, true, true, false) + if err != nil { + fmt.Println("Error calling JOIN: ", err) + return + } + logInputAndOutput(nil, joinData) - _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) + // `/v2/admin/list-operations` + logMethod("/v2/admin/list-operations") + listOperationsData, err := fc.ListOperations(10, &fc.ActiveFederationId) if err != nil { - fmt.Println("Error awaiting deposit: ", err) + fmt.Println("Error calling JOIN: ", err) return } + logInputAndOutput(nil, listOperationsData) } -func TestWithdraw(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestNewFedimintClient(t *testing.T) { +// fc := CreateNewFedimintClient() +// assert.NotNil(t, fc) - withdrawRequest := modules.OnchainWithdrawRequest{ - Address: "UNKNOWN", - AmountSat: 10000, - } +// assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") +// assert.Equal(t, fc.Password, "password") +// assert.Equal(t, fc.ActiveFederationId, "federation123") - withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) +// assert.Equal(t, fc, fc.Ln.Client) +// assert.Equal(t, fc, fc.Onchain.Client) +// assert.Equal(t, fc, fc.Mint.Client) +// } - assert.NotEqual(t, withdrawResponse, nil) +// func TestGetActiveFederationId(t *testing.T) { +// fc := CreateNewFedimintClient() - // Intentionally make an error (like - wrong ActiveFederationId/request) - wrong_fed_id := "12112" - _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) - assert.NotEqual(t, err, nil) -} +// fedId := fc.GetActiveFederationId() +// assert.Equal(t, fedId, "federation123") +// } -func TestAwaitWithdraw(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestSetActiveFederationId(t *testing.T) { +// fc := CreateNewFedimintClient() +// new_fedId := "New_federation123" - depositAddressRequest := modules.OnchainDepositAddressRequest{ - Timeout: 3600, - } - depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// fedId_prev := fc.ActiveFederationId +// fc.SetActiveFederationId(new_fedId, false) +// fedId_now := fc.ActiveFederationId +// assert.Equal(t, fedId_now, "New_federation123") +// assert.NotEqual(t, fedId_now, fedId_prev) +// } - awaitDepositRequest := modules.OnchainAwaitDepositRequest{ - OperationId: depositResponse.OperationId, - } +// //////////// +// // Onchain // +// //////////// - awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, awaitDepositResponse, nil) - assert.Equal(t, awaitDepositResponse.Status, nil) - } else { - assert.Equal(t, err, nil) - // println(awaitDepositResponse.Status) - assert.NotEqual(t, awaitDepositResponse.Status, nil) - } +// func TestCreateDepositAddress(t *testing.T) { +// fc := CreateNewFedimintClient() - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// depositAddressRequest := modules.OnchainDepositAddressRequest{ +// Timeout: 3600, +// } + +// depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, depositResponse, nil) +// assert.Equal(t, depositResponse.OperationId, nil) +// assert.Equal(t, depositResponse.Address, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, depositResponse.OperationId, nil) +// assert.NotEqual(t, depositResponse.Address, nil) +// } + +// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ +// OperationId: depositResponse.OperationId, +// } + +// _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// fmt.Println("Error awaiting deposit: ", err) +// return +// } +// } + +// func TestWithdraw(t *testing.T) { +// fc := CreateNewFedimintClient() -////////// -// mint // -////////// +// withdrawRequest := modules.OnchainWithdrawRequest{ +// Address: "UNKNOWN", +// AmountSat: 10000, +// } + +// withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) + +// assert.NotEqual(t, withdrawResponse, nil) -// func TestReissue(t *testing.T) { +// // Intentionally make an error (like - wrong ActiveFederationId/request) +// wrong_fed_id := "12112" +// _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) +// assert.NotEqual(t, err, nil) +// } + +// func TestAwaitWithdraw(t *testing.T) { // fc := CreateNewFedimintClient() -// oobNotesData := modules.OOBNotes { +// depositAddressRequest := modules.OnchainDepositAddressRequest{ +// Timeout: 3600, +// } +// depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ +// OperationId: depositResponse.OperationId, // } + +// awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, awaitDepositResponse, nil) +// assert.Equal(t, awaitDepositResponse.Status, nil) +// } else { +// assert.Equal(t, err, nil) +// // println(awaitDepositResponse.Status) +// assert.NotEqual(t, awaitDepositResponse.Status, nil) +// } + +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) // } -func TestSpend(t *testing.T) { - fc := CreateNewFedimintClient() +// ////////// +// // mint // +// ////////// - spendRequest := modules.MintSpendRequest{ - AmountMsat: 10000, - AllowOverpay: true, - Timeout: 3600, - } +// // func TestReissue(t *testing.T) { +// // fc := CreateNewFedimintClient() - spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, spendResponse, nil) - assert.Equal(t, spendResponse.OperationId, nil) - assert.Equal(t, spendResponse.Notes, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, spendResponse, nil) - assert.NotEqual(t, spendResponse.OperationId, nil) - assert.NotEqual(t, spendResponse.Notes, nil) - } +// // oobNotesData := modules.OOBNotes { - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // } +// // } -// func TestValidate(t *testing.T) { +// func TestSpend(t *testing.T) { // fc := CreateNewFedimintClient() -// } +// spendRequest := modules.MintSpendRequest{ +// AmountMsat: 10000, +// AllowOverpay: true, +// Timeout: 3600, +// } -//////// -// Ln // -//////// +// spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, spendResponse, nil) +// assert.Equal(t, spendResponse.OperationId, nil) +// assert.Equal(t, spendResponse.Notes, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, spendResponse, nil) +// assert.NotEqual(t, spendResponse.OperationId, nil) +// assert.NotEqual(t, spendResponse.Notes, nil) +// } -func TestCreateInvoice(t *testing.T) { - fc := CreateNewFedimintClient() +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } - expiryTime := 3600 - GatewayID := "test_GatewayID" - invoiceRequest := modules.LnInvoiceRequest{ - AmountMsat: 10000, - Description: "test", - ExpiryTime: &expiryTime, - } +// // func TestValidate(t *testing.T) { +// // fc := CreateNewFedimintClient() - invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, invoiceResponse, nil) - assert.Equal(t, invoiceResponse.OperationId, nil) - assert.Equal(t, invoiceResponse.Invoice, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, invoiceResponse, nil) - assert.NotEqual(t, invoiceResponse.OperationId, nil) - assert.NotEqual(t, invoiceResponse.Invoice, nil) - } +// // } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// //////// +// // Ln // +// //////// -func TestAwaitInvoice(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestCreateInvoice(t *testing.T) { +// fc := CreateNewFedimintClient() - awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ - OperationId: "TestAwaitInvoice", - } +// expiryTime := 3600 +// GatewayID := "test_GatewayID" +// invoiceRequest := modules.LnInvoiceRequest{ +// AmountMsat: 10000, +// Description: "test", +// ExpiryTime: &expiryTime, +// } - infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, infoResponse, nil) - assert.Equal(t, infoResponse.DenominationsMsat, nil) - assert.Equal(t, infoResponse.FederationID, nil) - assert.Equal(t, infoResponse.Meta, nil) - assert.Equal(t, infoResponse.Network, nil) - assert.Equal(t, infoResponse.TotalAmountMsat, nil) - assert.Equal(t, infoResponse.TotalNumNotes, nil) - assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) - } else { - assert.Equal(t, err, nil) - assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) - assert.NotEqual(t, infoResponse, nil) - assert.NotEqual(t, infoResponse.Meta, nil) - assert.NotEqual(t, infoResponse.Network, nil) - assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) - assert.NotEqual(t, infoResponse.TotalNumNotes, nil) - assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) - } +// invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, invoiceResponse, nil) +// assert.Equal(t, invoiceResponse.OperationId, nil) +// assert.Equal(t, invoiceResponse.Invoice, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, invoiceResponse, nil) +// assert.NotEqual(t, invoiceResponse.OperationId, nil) +// assert.NotEqual(t, invoiceResponse.Invoice, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "" - _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } -func TestPay(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestAwaitInvoice(t *testing.T) { +// fc := CreateNewFedimintClient() - LnurlComment := "test_LnurlComment" - GatewayID := "test_GatewayID" - AmountMsat := uint64(10000) - lnPayRequest := modules.LnPayRequest{ - PaymentInfo: "TestPayment", - AmountMsat: &AmountMsat, - LnurlComment: &LnurlComment, - } +// awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ +// OperationId: "TestAwaitInvoice", +// } - lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.ContractId, nil) - assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.PaymentType, nil) - assert.Equal(t, lnPayResponse.PperationId, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.ContractId, nil) - assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.PaymentType, nil) - assert.NotEqual(t, lnPayResponse.PperationId, nil) - } +// infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, infoResponse, nil) +// assert.Equal(t, infoResponse.DenominationsMsat, nil) +// assert.Equal(t, infoResponse.FederationID, nil) +// assert.Equal(t, infoResponse.Meta, nil) +// assert.Equal(t, infoResponse.Network, nil) +// assert.Equal(t, infoResponse.TotalAmountMsat, nil) +// assert.Equal(t, infoResponse.TotalNumNotes, nil) +// assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) +// assert.NotEqual(t, infoResponse, nil) +// assert.NotEqual(t, infoResponse.Meta, nil) +// assert.NotEqual(t, infoResponse.Network, nil) +// assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) +// assert.NotEqual(t, infoResponse.TotalNumNotes, nil) +// assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "" +// _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } -// func TestAwaitPay(t *testing.T) { +// func TestPay(t *testing.T) { // fc := CreateNewFedimintClient() -// awaitLnPayRequest := modules.AwaitLnPayRequest{ -// OperationId: "TestAwaitLnPay", +// LnurlComment := "test_LnurlComment" +// GatewayID := "test_GatewayID" +// AmountMsat := uint64(10000) +// lnPayRequest := modules.LnPayRequest{ +// PaymentInfo: "TestPayment", +// AmountMsat: &AmountMsat, +// LnurlComment: &LnurlComment, // } -// lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) // if err != nil { // assert.Equal(t, lnPayResponse, nil) -// assert.Equal(t, lnPayResponse.Contract_id, nil) +// assert.Equal(t, lnPayResponse.ContractId, nil) // assert.Equal(t, lnPayResponse.Fee, nil) -// assert.Equal(t, lnPayResponse.Payment_type, nil) -// assert.Equal(t, lnPayResponse.Pperation_id, nil) +// assert.Equal(t, lnPayResponse.PaymentType, nil) +// assert.Equal(t, lnPayResponse.PperationId, nil) // } else { // assert.Equal(t, err, nil) // assert.NotEqual(t, lnPayResponse, nil) -// assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// assert.NotEqual(t, lnPayResponse.ContractId, nil) // assert.NotEqual(t, lnPayResponse.Fee, nil) -// assert.NotEqual(t, lnPayResponse.Payment_type, nil) -// assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// assert.NotEqual(t, lnPayResponse.PaymentType, nil) +// assert.NotEqual(t, lnPayResponse.PperationId, nil) // } // // intentionally giving wrong parameters // wrong_fed_id := "12112" -// _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) // assert.NotEqual(t, err1, nil) // } -func TestListGateways(t *testing.T) { - fc := CreateNewFedimintClient() +// // func TestAwaitPay(t *testing.T) { +// // fc := CreateNewFedimintClient() + +// // awaitLnPayRequest := modules.AwaitLnPayRequest{ +// // OperationId: "TestAwaitLnPay", +// // } + +// // lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// // if err != nil { +// // assert.Equal(t, lnPayResponse, nil) +// // assert.Equal(t, lnPayResponse.Contract_id, nil) +// // assert.Equal(t, lnPayResponse.Fee, nil) +// // assert.Equal(t, lnPayResponse.Payment_type, nil) +// // assert.Equal(t, lnPayResponse.Pperation_id, nil) +// // } else { +// // assert.Equal(t, err, nil) +// // assert.NotEqual(t, lnPayResponse, nil) +// // assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// // assert.NotEqual(t, lnPayResponse.Fee, nil) +// // assert.NotEqual(t, lnPayResponse.Payment_type, nil) +// // assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// // } + +// // // intentionally giving wrong parameters +// // wrong_fed_id := "12112" +// // _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// // assert.NotEqual(t, err1, nil) +// // } + +// func TestListGateways(t *testing.T) { +// fc := CreateNewFedimintClient() - gatewaysResponse, err := fc.Ln.ListGateways() - if err != nil { - assert.Equal(t, gatewaysResponse, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, gatewaysResponse, nil) - } -} +// gatewaysResponse, err := fc.Ln.ListGateways() +// if err != nil { +// assert.Equal(t, gatewaysResponse, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, gatewaysResponse, nil) +// } +// } -func TestSwitchGateway(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestSwitchGateway(t *testing.T) { +// fc := CreateNewFedimintClient() - switchGatewayRequest := modules.SwitchGatewayRequest{ - GatewayId: "TestGateway1", - } +// switchGatewayRequest := modules.SwitchGatewayRequest{ +// GatewayId: "TestGateway1", +// } - gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, gatewayResponse, nil) - assert.Equal(t, gatewayResponse.Active, true) - assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) - } else { - assert.Equal(t, err, nil) - assert.Equal(t, gatewayResponse.Active, true) - assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) - } +// gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, gatewayResponse, nil) +// assert.Equal(t, gatewayResponse.Active, true) +// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.Equal(t, gatewayResponse.Active, true) +// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } From 9a638e071ac2f8cd4c11889e2f1d28b6ec087e59 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 01:11:32 +0530 Subject: [PATCH 05/23] fix::> justfile.local.just updated --- justfile.local.just | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile.local.just b/justfile.local.just index 4b54102..98606db 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -10,5 +10,8 @@ test-ts: test-go: cd wrappers/fedimint-go && go run cmd/main.go +test-go-pps: + cd wrappers/fedimint-go && go run pkg/fedimint/client_test.go + wscat: mprocs -c mprocs-wscat.yaml From 85dff22edd6db2a2413f8c7039161a65601b2b9c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 11:57:31 +0530 Subject: [PATCH 06/23] fix::> Added test suite for LIGHTNING METHODS updated --- justfile.local.just | 2 +- .../fedimint-go/pkg/fedimint/client_test.go | 83 ++++++++++++++++++- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/justfile.local.just b/justfile.local.just index 98606db..f0f41c8 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -11,7 +11,7 @@ test-go: cd wrappers/fedimint-go && go run cmd/main.go test-go-pps: - cd wrappers/fedimint-go && go run pkg/fedimint/client_test.go + cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 9fa0ccc..f5224f0 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -24,7 +24,7 @@ func logMethod(method string) { func logInputAndOutput(input interface{}, output interface{}) { fmt.Println("Input: ", input) fmt.Println("Output: ", output) - fmt.Println("--------------------") + fmt.Println("====================") } // BIG ISSUE // @@ -160,16 +160,91 @@ func TestFedimintGo(t *testing.T) { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(nil, joinData) + logInputAndOutput(inviteCode, joinData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") - listOperationsData, err := fc.ListOperations(10, &fc.ActiveFederationId) + listOperationsData, err := fc.ListOperations(10, nil) if err != nil { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(nil, listOperationsData) + logInputAndOutput([]interface{}{10}, listOperationsData) + + /////////////////////// + // LIGHTNING METHODS // + /////////////////////// + + // `/v2/ln/list-gateways` + gatewayList, err := fc.Ln.ListGateways() + if err != nil { + fmt.Println("Error calling LIST_GATEWAYS: ", err) + return + } + logInputAndOutput(nil, gatewayList) + + // `/v2/ln/invoice` + logMethod("/v2/ln/invoice") + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) + if err != nil { + fmt.Println("Error calling INVOICE: ", err) + return + } + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) + + // `/v2/ln/pay` + logMethod("/v2/ln/pay") + payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + if err != nil { + fmt.Println("Error calling PAY: ", err) + return + } + logInputAndOutput(invoiceData.Invoice, payData) + + // /v2/ln/await-invoice + logMethod("/v2/ln/await-invoice") + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_INVOICE: ", err) + return + } + logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + // `/v1/ln/invoice-external-pubkey-tweaked` + logMethod("/v1/ln/invoice-external-pubkey-tweaked") + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, nil) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + // `/v1/ln/invoice-external-pubkey` + logMethod("/v1/ln/invoice-external-pubkey") + invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) } // func TestNewFedimintClient(t *testing.T) { From 281852f13d8f66612e03c70f498260607a63429d Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 12:46:57 +0530 Subject: [PATCH 07/23] fix::> changed the type of field in DecodeNotesResponse struct and MintSpendResponse --- wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go index 1b6c5a5..a743b6b 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go @@ -63,7 +63,7 @@ type DecodeNotesRequest struct { } type DecodeNotesResponse struct { - NotesJson string `json:"notesJson"` + NotesJson NotesJson `json:"notesJson"` } type EncodeNotesRequest struct { @@ -89,8 +89,8 @@ type MintSpendRequest struct { } type MintSpendResponse struct { - OperationId string `json:"operationId"` - Notes OOBNotes `json:"notes"` + OperationId string `json:"operationId"` + Notes string `json:"notes"` } type MintValidateRequest struct { From f9d5545ef2fb04ceb3b6612115e070f74386127c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 12:48:21 +0530 Subject: [PATCH 08/23] fix::> Added test suite for MINT METHODS --- .../fedimint-go/pkg/fedimint/client_test.go | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index f5224f0..d370b28 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -245,6 +245,80 @@ func TestFedimintGo(t *testing.T) { return } logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) + + ////////////////// + // MINT METHODS // + ////////////////// + + // `/v2/mint/spend` + logMethod("/v2/mint/spend") + mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) + if err != nil { + fmt.Println("Error calling SPEND: ", err) + return + } + logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + // `/v2/mint/decode-notes` + logMethod("/v2/mint/decode-notes") + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(mintData.Notes, decodedData) + + // `/v2/mint/encode-notes` + logMethod("/v2/mint/encode-notes") + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(decodedData.NotesJson, encodedData) + + // `/v2/mint/validate` + logMethod("/v2/mint/validate") + validateData, err := fc.Mint.Validate(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling VALIDATE: ", err) + return + } + logInputAndOutput(mintData.Notes, validateData) + + // `/v2/mint/reissue` + logMethod("/v2/mint/reissue") + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling REISSUE: ", err) + return + } + logInputAndOutput(mintData.Notes, reissueData) + + // `/v2/mint/split` + logMethod("/v2/mint/split") + splitData, err := fc.Mint.Split(mintData.Notes) + if err != nil { + fmt.Println("Error calling SPLIT: ", err) + return + } + logInputAndOutput(mintData.Notes, splitData) + + // `/v2/mint/combine` + logMethod("/v2/mint/combine") + notesVec := func() []string { + result := make([]string, 0, len(splitData.Notes)) + for _, value := range splitData.Notes { + result = append(result, value) + } + return result + }() + combineData, err := fc.Mint.Combine(notesVec) + if err != nil { + fmt.Println("Error calling COMBINE: ", err) + return + } + logInputAndOutput(splitData.Notes, combineData) } // func TestNewFedimintClient(t *testing.T) { From 233752ddd830c3fbaddc681c36d8f3f985c12a10 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 16:10:02 +0530 Subject: [PATCH 09/23] fix::> Added test suite for ONCHAIN METHODS --- .../fedimint-go/pkg/fedimint/client_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index d370b28..3ced302 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -319,6 +319,37 @@ func TestFedimintGo(t *testing.T) { return } logInputAndOutput(splitData.Notes, combineData) + + ///////////////////// + // ONCHAIN METHODS // + ///////////////////// + + // `/v2/onchain/deposit-address` + logMethod("/v2/onchain/deposit-address") + addr, err := fc.Onchain.createDepositAddress(1000, nil) + if err != nil { + fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) + return + } + logInputAndOutput(1000, addr) + + // `/v2/onchain/withdraw` + logMethod("/v2/onchain/withdraw") + withdrawData, err := fc.Onchain.withdraw(addr.Address, 1000, nil) + if err != nil { + fmt.Println("Error calling WITHDRAW: ", err) + return + } + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + + // `/v2/onchain/await-deposit` + logMethod("/v2/onchain/await-deposit") + awaitDepositData, err := fc.Onchain.awaitDeposit(addr.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_DEPOSIT: ", err) + return + } + logInputAndOutput(addr.Address, awaitDepositData) } // func TestNewFedimintClient(t *testing.T) { From 79623b64dc04483528a9071073a4898648e98f99 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 2 Apr 2024 23:27:02 +0530 Subject: [PATCH 10/23] minor changes in structure --- wrappers/fedimint-go/pkg/fedimint/client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 9fc153a..28870bf 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -259,8 +259,8 @@ func (fc *FedimintClient) FederationIds() (types.FederationIdsResponse, error) { return response, nil } -func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret bool) (types.JoinResponse, error) { - request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: useManualSecret} +func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret *bool) (types.JoinResponse, error) { + request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: *useManualSecret} var response types.JoinResponse responseBody, err := fc.post("/admin/join", request) @@ -287,7 +287,7 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us // Onchain // //////////// -func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { +func (onchain *OnchainModule) CreateDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { request := modules.OnchainDepositAddressRequest{Timeout: timeout} resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, federationId) if err != nil { @@ -301,7 +301,7 @@ func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *st return &depositAddressResp, nil } -func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { +func (onchain *OnchainModule) AwaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { request := modules.OnchainAwaitDepositRequest{OperationId: operationId} resp, err := onchain.Client.postWithFederationId("/onchain/await-deposit", request, federationId) if err != nil { @@ -315,7 +315,7 @@ func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *str return &depositResp, nil } -func (onchain *OnchainModule) withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { +func (onchain *OnchainModule) Withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { request := modules.OnchainWithdrawRequest{Address: address, AmountSat: amountSat} resp, err := onchain.Client.postWithFederationId("/onchain/withdraw", request, federationId) if err != nil { From 38e4a2a000d53d4d53485f0846ff42cd4a4c748b Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 2 Apr 2024 23:28:56 +0530 Subject: [PATCH 11/23] fix::> Transfered all TEST function to main.go and mirrored them with fedimint-ts --- wrappers/fedimint-go/cmd/main.go | 221 ++++++++++++++++++++++++++----- 1 file changed, 191 insertions(+), 30 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 73ac4c8..4c71646 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -64,95 +64,256 @@ func buildTestClient() *fedimint.FedimintClient { } func main() { - client := buildTestClient() + fc := buildTestClient() keyPair := newKeyPair() - fmt.Println("Generated key pair: ", keyPair) + fmt.Printf("Generated Key Pair: ") + fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) + fmt.Printf(" Public Key: %s\n", keyPair.PublicKey) + + /////////////////// + // ADMIN METHODS // + /////////////////// - // ADMIN METHODS // `/v2/admin/config` logMethod("/v2/admin/config") - data, err := client.Config() + data, err := fc.Config() if err != nil { - fmt.Println("Error calling config: ", err) + fmt.Println("Error calling CONFIG: ", err) return } logInputAndOutput(nil, data) // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = client.DiscoverVersion(1) + data, err = fc.DiscoverVersion(1) // TS-mirror dont use any parameters if err != nil { - fmt.Println("Error calling discoverVersion: ", err) + fmt.Println("Error calling VERSION: ", err) return } - logInputAndOutput(nil, data) + logInputAndOutput(1, data) - // `/v2/admin/federation-ids` + // `/v2/admin/federation-ids logMethod("/v2/admin/federation-ids") - federationIds, err := client.FederationIds() + federationIds, err := fc.FederationIds() if err != nil { - fmt.Println("Error calling federationIds: ", err) + fmt.Println("Error calling FEDERATION_IDS: ", err) return } logInputAndOutput(nil, federationIds) // `/v2/admin/info` logMethod("/v2/admin/info") - infoData, err := client.Info() + infoData, err := fc.Info() if err != nil { - fmt.Println("Error calling info: ", err) + fmt.Println("Error calling INFO: ", err) return } logInputAndOutput(nil, infoData) // `/v2/admin/join` - inviteCode := os.Getenv("FEDIMINT_CLIENTD_INVITE_CODE") + inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") if inviteCode == "" { inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } logMethod("/v2/admin/join") - joinData, err := client.Join(inviteCode, true, true, false) + joinData, err := fc.Join(inviteCode, true, true, nil) if err != nil { - fmt.Println("Error calling join: ", err) + fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(map[string]interface{}{"inviteCode": inviteCode}, joinData) + logInputAndOutput(inviteCode, joinData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") - listOperationsData, err := client.ListOperations(10, nil) + listOperationsData, err := fc.ListOperations(10, nil) if err != nil { - fmt.Println("Error calling listOperations: ", err) + fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(map[string]interface{}{"limit": 10}, listOperationsData) + logInputAndOutput([]interface{}{10}, listOperationsData) + + /////////////////////// + // LIGHTNING METHODS // + /////////////////////// - // LIGHTNING METHODS // `/v2/ln/list-gateways` logMethod("/v2/ln/list-gateways") - listGatewaysData, err := client.Ln.ListGateways() + gatewayList, err := fc.Ln.ListGateways() if err != nil { - fmt.Println("Error calling listGateways: ", err) + fmt.Println("Error calling LIST_GATEWAYS: ", err) return } - logInputAndOutput(nil, listGatewaysData) + logInputAndOutput(nil, gatewayList) // `/v2/ln/invoice` logMethod("/v2/ln/invoice") - invoiceData, err := client.Ln.CreateInvoice(10000, "test") + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) if err != nil { - fmt.Println("Error calling createInvoice: ", err) + fmt.Println("Error calling INVOICE: ", err) return } - logInputAndOutput(map[string]interface{}{"amountMsat": 10000, "description": "test"}, invoiceData) + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) // `/v2/ln/pay` logMethod("/v2/ln/pay") - payData, err := client.Ln.Pay(invoiceData.Invoice, nil) + payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + if err != nil { + fmt.Println("Error calling PAY: ", err) + return + } + logInputAndOutput(invoiceData.Invoice, payData) + + // /v2/ln/await-invoice + logMethod("/v2/ln/await-invoice") + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_INVOICE: ", err) + return + } + logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + // `/v1/ln/invoice-external-pubkey-tweaked` + logMethod("/v1/ln/invoice-external-pubkey-tweaked") + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + // pay the invoice + _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + activeFederationID := fc.GetActiveFederationId() + claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, &activeFederationID) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + // // `/v1/ln/invoice-external-pubkey` + // logMethod("/v1/ln/invoice-external-pubkey") + // invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) + // if err != nil { + // fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) + // return + // } + // logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) + + // // `/v1/ln/claim-external-pubkey-tweaked` + // logMethod("/v1/ln/claim-external-pubkey-tweaked") + // claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) + // if err != nil { + // fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + // return + // } + // logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) + + ////////////////// + // MINT METHODS // + ////////////////// + + // `/v2/mint/spend` + logMethod("/v2/mint/spend") + mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) + if err != nil { + fmt.Println("Error calling SPEND: ", err) + return + } + logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + // `/v2/mint/decode-notes` + logMethod("/v2/mint/decode-notes") + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(mintData.Notes, decodedData) + + // `/v2/mint/encode-notes` + logMethod("/v2/mint/encode-notes") + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(decodedData.NotesJson, encodedData) + + // `/v2/mint/validate` + logMethod("/v2/mint/validate") + validateData, err := fc.Mint.Validate(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling VALIDATE: ", err) + return + } + logInputAndOutput(mintData.Notes, validateData) + + // `/v2/mint/reissue` + logMethod("/v2/mint/reissue") + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling REISSUE: ", err) + return + } + logInputAndOutput(mintData.Notes, reissueData) + + // `/v2/mint/split` + logMethod("/v2/mint/split") + splitData, err := fc.Mint.Split(mintData.Notes) if err != nil { - fmt.Println("Error calling pay: ", err) + fmt.Println("Error calling SPLIT: ", err) return } - logInputAndOutput(map[string]interface{}{"paymentInfo": invoiceData.Invoice}, payData) + logInputAndOutput(mintData.Notes, splitData) + + // `/v2/mint/combine` + logMethod("/v2/mint/combine") + notesVec := func() []string { + result := make([]string, 0, len(splitData.Notes)) + for _, value := range splitData.Notes { + result = append(result, value) + } + return result + }() + combineData, err := fc.Mint.Combine(notesVec) + if err != nil { + fmt.Println("Error calling COMBINE: ", err) + return + } + logInputAndOutput(splitData.Notes, combineData) + + ///////////////////// + // ONCHAIN METHODS // + ///////////////////// + + // `/v2/onchain/deposit-address` + logMethod("/v2/onchain/deposit-address") + addr, err := fc.Onchain.CreateDepositAddress(1000, nil) + if err != nil { + fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) + return + } + logInputAndOutput(1000, addr) + + // `/v2/onchain/withdraw` + logMethod("/v2/onchain/withdraw") + withdrawData, err := fc.Onchain.Withdraw(addr.Address, 1000, nil) + if err != nil { + fmt.Println("Error calling WITHDRAW: ", err) + return + } + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + + // `/v2/onchain/await-deposit` + logMethod("/v2/onchain/await-deposit") + // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) + // if err != nil { + // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) + // return + // } + // logInputAndOutput(addr.Address, awaitDepositData) } From acdc0b66b7da0c18c03137d0aca0ccde40e1d7bf Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Apr 2024 00:01:30 +0530 Subject: [PATCH 12/23] fix::> updated some parameters --- wrappers/fedimint-go/cmd/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 4c71646..8feea64 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -85,7 +85,7 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) // TS-mirror dont use any parameters + data, err = fc.DiscoverVersion(nil) if err != nil { fmt.Println("Error calling VERSION: ", err) return @@ -185,8 +185,7 @@ func main() { // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked") - activeFederationID := fc.GetActiveFederationId() - claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, &activeFederationID) + claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, fc.GetActiveFederationId()) if err != nil { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return @@ -226,7 +225,7 @@ func main() { // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") - decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) return @@ -235,7 +234,7 @@ func main() { // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") - encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) return From 493115278541058b9ed3d11caa9bd1e04a48f254 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Apr 2024 00:03:21 +0530 Subject: [PATCH 13/23] fix::> Made some changes in parameters of func --- wrappers/fedimint-go/pkg/fedimint/client.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 28870bf..8794b07 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -216,8 +216,8 @@ func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *st return err } -func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { - request := types.DiscoverVersionRequest{Threshold: threshold} +func (fc *FedimintClient) DiscoverVersion(threshold *uint16) (*types.FedimintResponse, error) { + request := types.DiscoverVersionRequest{Threshold: *threshold} resp, err := fc.post("/admin/discover-version", request) if err != nil { return nil, err @@ -333,9 +333,9 @@ func (onchain *OnchainModule) Withdraw(address string, amountSat int, federation // mint // ////////// -func (mint *MintModule) DecodeNotes(notes string, federationId *string) (*modules.DecodeNotesResponse, error) { +func (mint *MintModule) DecodeNotes(notes string) (*modules.DecodeNotesResponse, error) { request := modules.DecodeNotesRequest{Notes: notes} - resp, err := mint.Client.postWithFederationId("/mint/decode-notes", request, federationId) + resp, err := mint.Client.post("/mint/decode-notes", request) if err != nil { return nil, err } @@ -347,13 +347,13 @@ func (mint *MintModule) DecodeNotes(notes string, federationId *string) (*module return &decodeResp, nil } -func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson, federationId *string) (*modules.EncodeNotesResponse, error) { +func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson) (*modules.EncodeNotesResponse, error) { notesJsonStr, err := json.Marshal(notesJson) if err != nil { return nil, err } request := modules.EncodeNotesRequest{NotesJsonStr: string(notesJsonStr)} - resp, err := mint.Client.postWithFederationId("/mint/encode-notes", request, federationId) + resp, err := mint.Client.post("/mint/encode-notes", request) if err != nil { return nil, err } @@ -517,9 +517,9 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) return &infoResp, nil } -func (ln *LnModule) ClaimPubkeyReceiveTweaked(privateKey string, tweaks []uint64, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, federationId string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyTweakedRequest{PrivateKey: privateKey, Tweaks: tweaks} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, federationId) + resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, &federationId) if err != nil { return nil, err } From d940c97ce4a611827432e5fc947cbab52b1045c4 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sat, 6 Apr 2024 00:19:22 +0530 Subject: [PATCH 14/23] fix::> Mirrored python tests with go tests + updated just.local files --- justfile.local.just | 3 --- wrappers/fedimint-go/cmd/main.go | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/justfile.local.just b/justfile.local.just index 85e06eb..178441d 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -16,8 +16,5 @@ test-py-async: test-go: cd wrappers/fedimint-go && go run cmd/main.go -test-go-pps: - cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go - wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 8feea64..104cf24 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -182,6 +182,7 @@ func main() { logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) // pay the invoice _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) + fmt.Println("Paid locked invoice!") // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked") @@ -305,14 +306,14 @@ func main() { return } logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + fmt.Println("Done: All methods tested successfully!") // `/v2/onchain/await-deposit` - logMethod("/v2/onchain/await-deposit") + // logMethod("/v2/onchain/await-deposit") // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) // if err != nil { // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) // return // } // logInputAndOutput(addr.Address, awaitDepositData) - } From 8f795abcc7974edd313a1aff2cbba55277ebb068 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sat, 6 Apr 2024 01:20:58 +0530 Subject: [PATCH 15/23] fix::> discover_version now takes threshold as a copulsory input --- wrappers/fedimint-go/cmd/main.go | 2 +- wrappers/fedimint-go/pkg/fedimint/client.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 104cf24..2d30c1b 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -85,7 +85,7 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(nil) + data, err = fc.DiscoverVersion(1) if err != nil { fmt.Println("Error calling VERSION: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 8794b07..68ab816 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -216,8 +216,8 @@ func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *st return err } -func (fc *FedimintClient) DiscoverVersion(threshold *uint16) (*types.FedimintResponse, error) { - request := types.DiscoverVersionRequest{Threshold: *threshold} +func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { + request := types.DiscoverVersionRequest{Threshold: threshold} resp, err := fc.post("/admin/discover-version", request) if err != nil { return nil, err From 12af8824b01dfe4ce4786db37329710e11ff7bf9 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 09:40:52 +0530 Subject: [PATCH 16/23] fix::> Codebase cleanup --- wrappers/fedimint-go/cmd/main.go | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 2d30c1b..fe15472 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -193,24 +193,6 @@ func main() { } logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) - // // `/v1/ln/invoice-external-pubkey` - // logMethod("/v1/ln/invoice-external-pubkey") - // invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) - // if err != nil { - // fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) - // return - // } - // logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) - - // // `/v1/ln/claim-external-pubkey-tweaked` - // logMethod("/v1/ln/claim-external-pubkey-tweaked") - // claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) - // if err != nil { - // fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - // return - // } - // logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) - ////////////////// // MINT METHODS // ////////////////// @@ -307,13 +289,4 @@ func main() { } logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) fmt.Println("Done: All methods tested successfully!") - - // `/v2/onchain/await-deposit` - // logMethod("/v2/onchain/await-deposit") - // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) - // if err != nil { - // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) - // return - // } - // logInputAndOutput(addr.Address, awaitDepositData) } From 146341a08d97af71d07a00ca5765cbee19903fc4 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 10:41:25 +0530 Subject: [PATCH 17/23] fix::> discover_version deserialization done + signal SIGSEGV Error treated --- wrappers/fedimint-go/cmd/main.go | 25 ++++++++++++++++----- wrappers/fedimint-go/pkg/fedimint/client.go | 4 ++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index fe15472..7985978 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/hex" + "encoding/json" "fedimint-go-client/pkg/fedimint" "fmt" "os" @@ -85,12 +86,25 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) + discoverResponseData, err := fc.DiscoverVersion(1) if err != nil { fmt.Println("Error calling VERSION: ", err) return } - logInputAndOutput(1, data) + + jsonBytes, err := json.Marshal(discoverResponseData) + if err != nil { + fmt.Println("Error marshaling JSON(discover-version):", err) + return + } + var fedimintResponseData interface{} + err = json.Unmarshal(jsonBytes, &fedimintResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(discover-version):", err) + return + } + + logInputAndOutput(1, fedimintResponseData) // `/v2/admin/federation-ids logMethod("/v2/admin/federation-ids") @@ -103,12 +117,13 @@ func main() { // `/v2/admin/info` logMethod("/v2/admin/info") - infoData, err := fc.Info() + infoDataResponse, err := fc.Info() if err != nil { fmt.Println("Error calling INFO: ", err) return } - logInputAndOutput(nil, infoData) + + logInputAndOutput(nil, infoDataResponse) // `/v2/admin/join` inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -116,7 +131,7 @@ func main() { inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } logMethod("/v2/admin/join") - joinData, err := fc.Join(inviteCode, true, true, nil) + joinData, err := fc.Join(inviteCode, true, true, false) if err != nil { fmt.Println("Error calling JOIN: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 68ab816..fc7d1fb 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -259,8 +259,8 @@ func (fc *FedimintClient) FederationIds() (types.FederationIdsResponse, error) { return response, nil } -func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret *bool) (types.JoinResponse, error) { - request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: *useManualSecret} +func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret bool) (types.JoinResponse, error) { + request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: useManualSecret} var response types.JoinResponse responseBody, err := fc.post("/admin/join", request) From e1d4cadba000ed902b87c8b0bf419a6a36d2ac44 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 11:41:04 +0530 Subject: [PATCH 18/23] fix::> added deserialize functionality to all outputs --- wrappers/fedimint-go/cmd/main.go | 274 ++++++++++++++++++++++++++++--- 1 file changed, 255 insertions(+), 19 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 7985978..8904831 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -123,7 +123,19 @@ func main() { return } - logInputAndOutput(nil, infoDataResponse) + jsonBytes, err = json.Marshal(infoDataResponse) + if err != nil { + fmt.Println("Error marshaling JSON(discover-version):", err) + return + } + var infoResponseData interface{} + err = json.Unmarshal(jsonBytes, &infoResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(discover-version):", err) + return + } + + logInputAndOutput(nil, infoResponseData) // `/v2/admin/join` inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -136,7 +148,20 @@ func main() { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(inviteCode, joinData) + + jsonBytes, err = json.Marshal(joinData) + if err != nil { + fmt.Println("Error marshaling JSON(join):", err) + return + } + var joinResponseData interface{} + err = json.Unmarshal(jsonBytes, &joinResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(join):", err) + return + } + + logInputAndOutput(inviteCode, joinResponseData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") @@ -145,7 +170,20 @@ func main() { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput([]interface{}{10}, listOperationsData) + + jsonBytes, err = json.Marshal(listOperationsData) + if err != nil { + fmt.Println("Error marshaling JSON(list-operations):", err) + return + } + var listOperationsResponseData interface{} + err = json.Unmarshal(jsonBytes, &listOperationsResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(list-operations):", err) + return + } + + logInputAndOutput([]interface{}{10}, listOperationsResponseData) /////////////////////// // LIGHTNING METHODS // @@ -158,7 +196,20 @@ func main() { fmt.Println("Error calling LIST_GATEWAYS: ", err) return } - logInputAndOutput(nil, gatewayList) + + jsonBytes, err = json.Marshal(gatewayList) + if err != nil { + fmt.Println("Error marshaling JSON(list-gateways):", err) + return + } + var gatewayListResponseData interface{} + err = json.Unmarshal(jsonBytes, &gatewayListResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(list-gateways):", err) + return + } + + logInputAndOutput(nil, gatewayListResponseData) // `/v2/ln/invoice` logMethod("/v2/ln/invoice") @@ -167,7 +218,20 @@ func main() { fmt.Println("Error calling INVOICE: ", err) return } - logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) + + jsonBytes, err = json.Marshal(invoiceData) + if err != nil { + fmt.Println("Error marshaling JSON(invoice):", err) + return + } + var invoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &invoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(invoice):", err) + return + } + + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceResponseData) // `/v2/ln/pay` logMethod("/v2/ln/pay") @@ -176,7 +240,20 @@ func main() { fmt.Println("Error calling PAY: ", err) return } - logInputAndOutput(invoiceData.Invoice, payData) + + jsonBytes, err = json.Marshal(payData) + if err != nil { + fmt.Println("Error marshaling JSON(pay):", err) + return + } + var payResponseData interface{} + err = json.Unmarshal(jsonBytes, &payResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(pay):", err) + return + } + + logInputAndOutput(invoiceData.Invoice, payResponseData) // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") @@ -185,7 +262,20 @@ func main() { fmt.Println("Error calling AWAIT_INVOICE: ", err) return } - logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + jsonBytes, err = json.Marshal(awaitInvoiceData) + if err != nil { + fmt.Println("Error marshaling JSON(await-invoice):", err) + return + } + var awaitInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &awaitInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(await-invoice):", err) + return + } + + logInputAndOutput(invoiceData.OperationId, awaitInvoiceResponseData) // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked") @@ -194,7 +284,20 @@ func main() { fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) return } - logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + + jsonBytes, err = json.Marshal(tweakInvoice) + if err != nil { + fmt.Println("Error marshaling JSON(await-invoice):", err) + return + } + var tweakInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &tweakInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(await-invoice):", err) + return + } + + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData) // pay the invoice _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) fmt.Println("Paid locked invoice!") @@ -206,7 +309,20 @@ func main() { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return } - logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + jsonBytes, err = json.Marshal(claimInvoice) + if err != nil { + fmt.Println("Error marshaling JSON(claim-external-pubkey-tweaked):", err) + return + } + var claimInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &claimInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(claim-external-pubkey-tweaked):", err) + return + } + + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoiceResponseData) ////////////////// // MINT METHODS // @@ -219,7 +335,20 @@ func main() { fmt.Println("Error calling SPEND: ", err) return } - logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + jsonBytes, err = json.Marshal(mintData) + if err != nil { + fmt.Println("Error marshaling JSON(spend):", err) + return + } + var mintResponseData interface{} + err = json.Unmarshal(jsonBytes, &mintResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(spend):", err) + return + } + + logInputAndOutput([]interface{}{3000, true, 1000}, mintResponseData) // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") @@ -228,7 +357,20 @@ func main() { fmt.Println("Error calling DECODE_NOTES: ", err) return } - logInputAndOutput(mintData.Notes, decodedData) + + jsonBytes, err = json.Marshal(decodedData) + if err != nil { + fmt.Println("Error marshaling JSON(decode-notes):", err) + return + } + var decodedResponseData interface{} + err = json.Unmarshal(jsonBytes, &decodedResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(decode-notes):", err) + return + } + + logInputAndOutput(mintData.Notes, decodedResponseData) // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") @@ -237,7 +379,20 @@ func main() { fmt.Println("Error calling DECODE_NOTES: ", err) return } - logInputAndOutput(decodedData.NotesJson, encodedData) + + jsonBytes, err = json.Marshal(encodedData) + if err != nil { + fmt.Println("Error marshaling JSON(encode-notes):", err) + return + } + var encodedResponseData interface{} + err = json.Unmarshal(jsonBytes, &encodedResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(encode-notes):", err) + return + } + + logInputAndOutput(decodedData.NotesJson, encodedResponseData) // `/v2/mint/validate` logMethod("/v2/mint/validate") @@ -246,7 +401,20 @@ func main() { fmt.Println("Error calling VALIDATE: ", err) return } - logInputAndOutput(mintData.Notes, validateData) + + jsonBytes, err = json.Marshal(validateData) + if err != nil { + fmt.Println("Error marshaling JSON(validate):", err) + return + } + var validateResponseData interface{} + err = json.Unmarshal(jsonBytes, &validateResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(validate):", err) + return + } + + logInputAndOutput(mintData.Notes, validateResponseData) // `/v2/mint/reissue` logMethod("/v2/mint/reissue") @@ -255,7 +423,20 @@ func main() { fmt.Println("Error calling REISSUE: ", err) return } - logInputAndOutput(mintData.Notes, reissueData) + + jsonBytes, err = json.Marshal(reissueData) + if err != nil { + fmt.Println("Error marshaling JSON(reissue):", err) + return + } + var reissueResponseData interface{} + err = json.Unmarshal(jsonBytes, &reissueResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(reissue):", err) + return + } + + logInputAndOutput(mintData.Notes, reissueResponseData) // `/v2/mint/split` logMethod("/v2/mint/split") @@ -264,7 +445,20 @@ func main() { fmt.Println("Error calling SPLIT: ", err) return } - logInputAndOutput(mintData.Notes, splitData) + + jsonBytes, err = json.Marshal(splitData) + if err != nil { + fmt.Println("Error marshaling JSON(split):", err) + return + } + var splitResponseData interface{} + err = json.Unmarshal(jsonBytes, &splitResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(split):", err) + return + } + + logInputAndOutput(mintData.Notes, splitResponseData) // `/v2/mint/combine` logMethod("/v2/mint/combine") @@ -280,7 +474,20 @@ func main() { fmt.Println("Error calling COMBINE: ", err) return } - logInputAndOutput(splitData.Notes, combineData) + + jsonBytes, err = json.Marshal(combineData) + if err != nil { + fmt.Println("Error marshaling JSON(split):", err) + return + } + var combineResponseData interface{} + err = json.Unmarshal(jsonBytes, &combineResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(split):", err) + return + } + + logInputAndOutput(splitData.Notes, combineResponseData) ///////////////////// // ONCHAIN METHODS // @@ -293,7 +500,20 @@ func main() { fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) return } - logInputAndOutput(1000, addr) + + jsonBytes, err = json.Marshal(addr) + if err != nil { + fmt.Println("Error marshaling JSON(deposit-address):", err) + return + } + var addrResponseData interface{} + err = json.Unmarshal(jsonBytes, &addrResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(deposit-address):", err) + return + } + + logInputAndOutput(1000, addrResponseData) // `/v2/onchain/withdraw` logMethod("/v2/onchain/withdraw") @@ -302,6 +522,22 @@ func main() { fmt.Println("Error calling WITHDRAW: ", err) return } - logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) - fmt.Println("Done: All methods tested successfully!") + + jsonBytes, err = json.Marshal(withdrawData) + if err != nil { + fmt.Println("Error marshaling JSON(withdraw):", err) + return + } + var withdrawResponseData interface{} + err = json.Unmarshal(jsonBytes, &withdrawResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(withdraw):", err) + return + } + + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawResponseData) + + fmt.Println("============================================") + fmt.Println("|| Done: All methods tested successfully! ||") + fmt.Println("============================================") } From 23690ce8ae1f5b89a3772003a7895a5c499afb6a Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Mon, 8 Apr 2024 11:03:16 -0700 Subject: [PATCH 19/23] fix: fix some tests plus nix flake plus cargo issues causing errors in go tests --- Cargo.lock | 187 +++-- fedimint-clientd/Cargo.toml | 2 +- fedimint-clientd/src/main.rs | 13 + flake.lock | 453 +----------- flake.nix | 20 +- wrappers/fedimint-go/cmd/main.go | 2 +- wrappers/fedimint-go/pkg/fedimint/client.go | 49 +- .../fedimint-go/pkg/fedimint/client_test.go | 673 ------------------ 8 files changed, 145 insertions(+), 1254 deletions(-) delete mode 100644 wrappers/fedimint-go/pkg/fedimint/client_test.go diff --git a/Cargo.lock b/Cargo.lock index dda7b61..14dc6b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,54 +76,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" - -[[package]] -name = "anstyle-parse" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "anyhow" version = "1.0.81" @@ -229,6 +181,17 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -299,7 +262,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00c055ee2d014ae5981ce1016374e8213682aa14d9bf40e48ab48b5f3ef20eaa" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "syn 2.0.53", @@ -696,49 +659,42 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ - "clap_builder", + "atty", + "bitflags 1.3.2", "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" -dependencies = [ - "anstream", - "anstyle", "clap_lex", - "strsim 0.11.0", + "indexmap 1.9.3", + "once_cell", + "strsim", + "termcolor", + "textwrap", ] [[package]] name = "clap_derive" -version = "4.5.3" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck 0.5.0", + "heck", + "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.53", + "syn 1.0.109", ] [[package]] name = "clap_lex" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" - -[[package]] -name = "colorchoice" -version = "1.0.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] [[package]] name = "concurrent-queue" @@ -834,7 +790,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.10.0", + "strsim", "syn 2.0.53", ] @@ -1697,7 +1653,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -1716,7 +1672,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.1.0", - "indexmap", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -1733,6 +1689,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.3" @@ -1750,10 +1712,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "heck" -version = "0.5.0" +name = "hermit-abi" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] [[package]] name = "hermit-abi" @@ -2058,6 +2023,16 @@ dependencies = [ "quote", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.2.5" @@ -2562,7 +2537,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", ] @@ -2639,7 +2614,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap", + "indexmap 2.2.5", "js-sys", "once_cell", "pin-project-lite", @@ -2700,6 +2675,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + [[package]] name = "overload" version = "0.1.1" @@ -3506,12 +3487,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strsim" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" - [[package]] name = "strum" version = "0.26.2" @@ -3524,7 +3499,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", @@ -3604,6 +3579,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + [[package]] name = "thiserror" version = "1.0.58" @@ -3825,7 +3815,7 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "indexmap", + "indexmap 2.2.5", "toml_datetime", "winnow", ] @@ -4027,12 +4017,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "validator" version = "0.17.0" @@ -4213,6 +4197,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/fedimint-clientd/Cargo.toml b/fedimint-clientd/Cargo.toml index 3606339..62d4199 100644 --- a/fedimint-clientd/Cargo.toml +++ b/fedimint-clientd/Cargo.toml @@ -37,7 +37,7 @@ bitcoin_hashes = "0.13.0" time = { version = "0.3.25", features = ["formatting"] } chrono = "0.4.31" futures-util = "0.3.30" -clap = { version = "4.4.13", features = ["derive", "env"] } +clap = { version = "3", features = ["derive", "env"] } multimint = { version = "0.3.0" } # multimint = { path = "../multimint" } axum-otel-metrics = "0.8.0" diff --git a/fedimint-clientd/src/main.rs b/fedimint-clientd/src/main.rs index b97b894..bc10420 100644 --- a/fedimint-clientd/src/main.rs +++ b/fedimint-clientd/src/main.rs @@ -31,6 +31,19 @@ enum Mode { Cashu, } +impl FromStr for Mode { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "rest" => Ok(Mode::Rest), + "ws" => Ok(Mode::Ws), + "cashu" => Ok(Mode::Cashu), + _ => Err(anyhow::anyhow!("Invalid mode")), + } + } +} + #[derive(Subcommand)] enum Commands { Start, diff --git a/flake.lock b/flake.lock index 29a1549..512adc3 100644 --- a/flake.lock +++ b/flake.lock @@ -1,50 +1,9 @@ { "nodes": { - "advisory-db": { - "flake": false, - "locked": { - "lastModified": 1706115649, - "narHash": "sha256-Qrqb54qGaRsFdLDj8EJtI5leFGFfqWHLRgC+t6KWlpQ=", - "owner": "rustsec", - "repo": "advisory-db", - "rev": "1d2202ea2b32fabd3307641010301bfe187ef11a", - "type": "github" - }, - "original": { - "owner": "rustsec", - "repo": "advisory-db", - "type": "github" - } - }, "android-nixpkgs": { "inputs": { "devshell": "devshell", - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "fedimint", - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1695500413, - "narHash": "sha256-yinrAWIc4XZbWQoXOYkUO0lCNQ5z/vMyl+QCYuIwdPc=", - "owner": "dpc", - "repo": "android-nixpkgs", - "rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4", - "type": "github" - }, - "original": { - "owner": "dpc", - "repo": "android-nixpkgs", - "rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4", - "type": "github" - } - }, - "android-nixpkgs_2": { - "inputs": { - "devshell": "devshell_2", - "flake-utils": "flake-utils_6", + "flake-utils": "flake-utils_2", "nixpkgs": [ "flakebox", "nixpkgs" @@ -65,51 +24,7 @@ "type": "github" } }, - "bundlers": { - "inputs": { - "nix-bundle": "nix-bundle", - "nix-utils": "nix-utils", - "nixpkgs": "nixpkgs_3" - }, - "locked": { - "lastModified": 1708548996, - "narHash": "sha256-U7DF6oLGaGm4SmfUnaK8X2Y36fprVd7EFr8sqV6Ocp8=", - "owner": "dpc", - "repo": "bundlers", - "rev": "e8aafe89a11ae0a5f3ce97d1d7d0fcfb354c79eb", - "type": "github" - }, - "original": { - "owner": "dpc", - "repo": "bundlers", - "rev": "e8aafe89a11ae0a5f3ce97d1d7d0fcfb354c79eb", - "type": "github" - } - }, "crane": { - "inputs": { - "nixpkgs": [ - "fedimint", - "flakebox", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1699217310, - "narHash": "sha256-xpW3VFUG7yE6UE6Wl0dhqencuENSkV7qpnpe9I8VbPw=", - "owner": "ipetkov", - "repo": "crane", - "rev": "d535642bbe6f377077f7c23f0febb78b1463f449", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "rev": "d535642bbe6f377077f7c23f0febb78b1463f449", - "type": "github" - } - }, - "crane_2": { "inputs": { "nixpkgs": [ "flakebox", @@ -134,7 +49,6 @@ "devshell": { "inputs": { "nixpkgs": [ - "fedimint", "flakebox", "android-nixpkgs", "nixpkgs" @@ -155,82 +69,13 @@ "type": "github" } }, - "devshell_2": { - "inputs": { - "nixpkgs": [ - "flakebox", - "android-nixpkgs", - "nixpkgs" - ], - "systems": "systems_6" - }, - "locked": { - "lastModified": 1695195896, - "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", - "owner": "numtide", - "repo": "devshell", - "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "fedimint": { - "inputs": { - "advisory-db": "advisory-db", - "bundlers": "bundlers", - "fenix": "fenix", - "flake-utils": "flake-utils_2", - "flakebox": "flakebox", - "nixpkgs": "nixpkgs_4" - }, - "locked": { - "lastModified": 1711990352, - "narHash": "sha256-IRaivPWz9SVmyFKsPT24OkNYO4WS+6WHhXyl0h0xDSM=", - "owner": "fedimint", - "repo": "fedimint", - "rev": "a41e3a7e31ce0f26058206a04f1cd49ef2b12fe3", - "type": "github" - }, - "original": { - "owner": "fedimint", - "ref": "v0.3.0", - "repo": "fedimint", - "type": "github" - } - }, "fenix": { - "inputs": { - "nixpkgs": [ - "fedimint", - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1708928609, - "narHash": "sha256-LcXC2NP/TzHMmJThZGG1e+7rht5HeuZK5WOirIDg+lU=", - "owner": "nix-community", - "repo": "fenix", - "rev": "e928fb6b5179ebd032c19afac5c461ccc0b6de55", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "fenix_2": { "inputs": { "nixpkgs": [ "flakebox", "nixpkgs" ], - "rust-analyzer-src": "rust-analyzer-src_2" + "rust-analyzer-src": "rust-analyzer-src" }, "locked": { "lastModified": 1699597299, @@ -247,82 +92,9 @@ } }, "flake-utils": { - "locked": { - "lastModified": 1623875721, - "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { "inputs": { "systems": "systems" }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, - "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_4": { - "inputs": { - "systems": [ - "fedimint", - "flakebox", - "systems" - ] - }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_5": { - "inputs": { - "systems": "systems_5" - }, "locked": { "lastModified": 1701680307, "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", @@ -337,9 +109,9 @@ "type": "github" } }, - "flake-utils_6": { + "flake-utils_2": { "inputs": { - "systems": "systems_7" + "systems": "systems_3" }, "locked": { "lastModified": 1694529238, @@ -355,7 +127,7 @@ "type": "github" } }, - "flake-utils_7": { + "flake-utils_3": { "inputs": { "systems": [ "flakebox", @@ -380,43 +152,13 @@ "inputs": { "android-nixpkgs": "android-nixpkgs", "crane": "crane", - "fenix": [ - "fedimint", - "fenix" - ], - "flake-utils": "flake-utils_4", + "fenix": "fenix", + "flake-utils": "flake-utils_3", "nixpkgs": [ - "fedimint", "nixpkgs" ], "systems": "systems_4" }, - "locked": { - "lastModified": 1709623646, - "narHash": "sha256-kqN+O/D+s2SKYfDdJUrmh1/tpc476gn+JU7JjjnkSik=", - "owner": "dpc", - "repo": "flakebox", - "rev": "27ecbf8f2b252dd843d0f58d45658eb56bb5e223", - "type": "github" - }, - "original": { - "owner": "dpc", - "repo": "flakebox", - "rev": "27ecbf8f2b252dd843d0f58d45658eb56bb5e223", - "type": "github" - } - }, - "flakebox_2": { - "inputs": { - "android-nixpkgs": "android-nixpkgs_2", - "crane": "crane_2", - "fenix": "fenix_2", - "flake-utils": "flake-utils_7", - "nixpkgs": [ - "nixpkgs" - ], - "systems": "systems_8" - }, "locked": { "lastModified": 1703201932, "narHash": "sha256-Uzf4pJaqlpRE5N+pR+YRfQcodzkYi5X1LbQLrQcPgZQ=", @@ -431,104 +173,7 @@ "type": "github" } }, - "nix-bundle": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1708548961, - "narHash": "sha256-WVA2EMhl/jk5GS84y20ExnIW03UyH43wRuoiySxHGZE=", - "owner": "dpc", - "repo": "nix-bundle", - "rev": "8ab9acfe0a31805de7899eddb8f3312d4e34a13d", - "type": "github" - }, - "original": { - "owner": "dpc", - "repo": "nix-bundle", - "rev": "8ab9acfe0a31805de7899eddb8f3312d4e34a13d", - "type": "github" - } - }, - "nix-utils": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1632973430, - "narHash": "sha256-9G8zo+0nfYAALV5umCyQR/2hVUFNH10JropBkyxZGGw=", - "owner": "juliosueiras-nix", - "repo": "nix-utils", - "rev": "b44e1ffd726aa03056db9df469efb497d8b9871b", - "type": "github" - }, - "original": { - "owner": "juliosueiras-nix", - "repo": "nix-utils", - "type": "github" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1620055814, - "narHash": "sha256-8LEHoYSJiL901bTMVatq+rf8y7QtWuZhwwpKE2fyaRY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-20.03-small", - "type": "indirect" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1629252929, - "narHash": "sha256-Aj20gmGBs8TG7pyaQqgbsqAQ6cB+TVuL18Pk3DPBxcQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3788c68def67ca7949e0864c27638d484389363d", - "type": "github" - }, - "original": { - "owner": "nixos", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1634782485, - "narHash": "sha256-psfh4OQSokGXG0lpq3zKFbhOo3QfoeudRcaUnwMRkQo=", - "path": "/nix/store/p53cz6rh27q40g9i0q98k3vfrz6lm12w-source", - "rev": "34ad3ffe08adfca17fcb4e4a47bb5f3b113687be", - "type": "path" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_4": { - "locked": { - "lastModified": 1709309926, - "narHash": "sha256-VZFBtXGVD9LWTecGi6eXrE0hJ/mVB3zGUlHImUs2Qak=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "79baff8812a0d68e24a836df0a364c678089e2c7", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_5": { "locked": { "lastModified": 1710695816, "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", @@ -546,30 +191,12 @@ }, "root": { "inputs": { - "fedimint": "fedimint", - "flake-utils": "flake-utils_5", - "flakebox": "flakebox_2", - "nixpkgs": "nixpkgs_5" + "flake-utils": "flake-utils", + "flakebox": "flakebox", + "nixpkgs": "nixpkgs" } }, "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1708878562, - "narHash": "sha256-IBHMNEe3lspVdIzjpM2OVZiBFmFw1DKtdgVN5G41pRc=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "5346002d07d09badaf37949bec68012d963d61fc", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "rust-analyzer-src_2": { "flake": false, "locked": { "lastModified": 1699552432, @@ -645,66 +272,6 @@ "repo": "default", "type": "github" } - }, - "systems_5": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_6": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_7": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_8": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 64fe806..c127cfc 100644 --- a/flake.nix +++ b/flake.nix @@ -10,21 +10,14 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - fedimint = { url = "github:fedimint/fedimint?ref=v0.3.0"; }; - flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flakebox, flake-utils, fedimint }: + outputs = { self, nixpkgs, flakebox, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let - nixpkgs = fedimint.inputs.nixpkgs; - pkgs = import nixpkgs { - inherit system; - overlays = fedimint.overlays.fedimint; - }; + pkgs = import nixpkgs { inherit system; }; lib = pkgs.lib; - fmLib = fedimint.lib.${system}; flakeboxLib = flakebox.lib.${system} { }; rustSrc = flakeboxLib.filterSubPaths { root = builtins.path { @@ -77,14 +70,7 @@ packages = { default = outputs.fedimint-clientd; }; devShells = flakeboxLib.mkShells { packages = [ ]; - nativeBuildInputs = [ - pkgs.mprocs - pkgs.go - pkgs.bun - fedimint.packages.${system}.devimint - fedimint.packages.${system}.gateway-pkgs - fedimint.packages.${system}.fedimint-pkgs - ]; + nativeBuildInputs = [ pkgs.mprocs pkgs.go pkgs.bun ]; }; }); } diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 8904831..5037003 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -191,7 +191,7 @@ func main() { // `/v2/ln/list-gateways` logMethod("/v2/ln/list-gateways") - gatewayList, err := fc.Ln.ListGateways() + gatewayList, err := fc.Ln.ListGateways(&fc.ActiveFederationId) if err != nil { fmt.Println("Error calling LIST_GATEWAYS: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index fc7d1fb..8aaf3ff 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -91,7 +91,7 @@ func (fc *FedimintClient) SetActiveGatewayId(gatewayId string) { func (fc *FedimintClient) UseDefaultGateway() error { // hits list_gateways and sets activeGatewayId to the first gateway - gateways, err := fc.Ln.ListGateways() + gateways, err := fc.Ln.ListGateways(&fc.ActiveFederationId) if err != nil { return fmt.Errorf("error getting gateways: %w", err) } @@ -117,33 +117,38 @@ func (fc *FedimintClient) post(endpoint string, body interface{}) ([]byte, error } func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{}, federationId *string) ([]byte, error) { - // Marshal the original body to JSON - originalBodyJSON, err := json.Marshal(body) + // Marshal the body to JSON + bodyJSON, err := json.Marshal(body) if err != nil { return nil, err } - // Unmarshal the JSON into a map to add federationId - var bodyMap map[string]interface{} - err = json.Unmarshal(originalBodyJSON, &bodyMap) - if err != nil { + // Initialize and convert JSON to map for manipulation + var bodyMap map[string]interface{} = make(map[string]interface{}) // Initialize the map here + if err := json.Unmarshal(bodyJSON, &bodyMap); err != nil { return nil, err } - // Add federationId to the map - effectiveFederationId := fc.ActiveFederationId + // If bodyMap is nil after unmarshaling, initialize it + if bodyMap == nil { + println("bodyMap is nil") + bodyMap = make(map[string]interface{}) + } + + // Set federationId in the body map if federationId != nil { - effectiveFederationId = *federationId + bodyMap["federationId"] = *federationId + } else { + bodyMap["federationId"] = fc.ActiveFederationId } - bodyMap["federationId"] = effectiveFederationId - // Marshal the modified map back to JSON + // Marshal the modified body back to JSON modifiedBodyJSON, err := json.Marshal(bodyMap) if err != nil { return nil, err } - // Use the modified JSON as the body for the POST request + // Make the POST request with the modified body return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) } @@ -154,13 +159,7 @@ func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, body return nil, err } - // Unmarshal the JSON into a map to add federationId - var bodyMap map[string]interface{} - err = json.Unmarshal(originalBodyJSON, &bodyMap) - if err != nil { - return nil, err - } - + var bodyMap = make(map[string]interface{}) // Add federationId to the map effectiveFederationId := fc.ActiveFederationId if federationId != nil { @@ -168,6 +167,12 @@ func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, body } bodyMap["federationId"] = effectiveFederationId + // Unmarshal the JSON into a map to add federationId + err = json.Unmarshal(originalBodyJSON, &bodyMap) + if err != nil { + return nil, err + } + // Add gatewayId to the map effectiveGatewayId := fc.ActiveGatewayId if gatewayId != nil { @@ -564,8 +569,8 @@ func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *st return &payResp, nil } -func (ln *LnModule) ListGateways() ([]modules.Gateway, error) { - resp, err := ln.Client.get("/ln/list-gateways") +func (ln *LnModule) ListGateways(federationId *string) ([]modules.Gateway, error) { + resp, err := ln.Client.postWithFederationId("/ln/list-gateways", nil, nil) if err != nil { return nil, err } diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go deleted file mode 100644 index 3ced302..0000000 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ /dev/null @@ -1,673 +0,0 @@ -// Client_tests -package fedimint - -import ( - "encoding/hex" - "fmt" - "log" - "os" - "testing" - - "github.com/btcsuite/btcd/btcec/v2" -) - -type KeyPair struct { - PrivateKey string - PublicKey string -} - -func logMethod(method string) { - fmt.Println("--------------------") - fmt.Println("Method:", method) -} - -func logInputAndOutput(input interface{}, output interface{}) { - fmt.Println("Input: ", input) - fmt.Println("Output: ", output) - fmt.Println("====================") -} - -// BIG ISSUE // -// func newKeyPair() KeyPair { -// var privateKey *big.Int -// var err error - -// for { -// privateKey, err = rand.Int(rand.Reader, secp256k1.S256().Params().N) -// if err != nil { -// log.Fatal(err) -// } -// if privateKey.Sign() > 0 && privateKey.Cmp(secp256k1.S256().Params().N) < 0 { -// break -// } -// } - -// // publicKey := secp256k1.PublicKey{} -// // secp256k1.S256().SerializePublicKey(publicKey[:], privateKey.Bytes()) - -// publicKey := secp256k1.PublicKey{} -// publicKey1 := secp256k1.PublicKey{ -// x: new(big.Int), -// y: new(big.Int), -// } -// //(publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) -// secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) - -// return KeyPair{ -// PrivateKey: hex.EncodeToString(privateKey.Bytes()), -// PublicKey: hex.EncodeToString(publicKey[:]), -// } -// } - -func newKeyPair() KeyPair { - privKey, err := btcec.NewPrivateKey() - if err != nil { - log.Fatal("Error generating private key:", err) - } - - // Get the corresponding public key - pubKey := privKey.PubKey() - - // Print the private and public keys - fmt.Printf("Private key: %x\n", privKey.Serialize()) - fmt.Printf("Public key: %x\n", pubKey.SerializeCompressed()) - - return KeyPair{ - PrivateKey: hex.EncodeToString(privKey.Serialize()), - PublicKey: hex.EncodeToString(pubKey.SerializeCompressed()), - } -} - -func CreateNewFedimintClient() *FedimintClient { - // Define test data - baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") - if baseURL == "" { - baseURL = "127.0.0.1:3333" - } - password := os.Getenv("FEDIMINT_CLIENTD_PASSWORD") - if password == "" { - password = "password" - } - activeFederationID := os.Getenv("FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID") - if activeFederationID == "" { - activeFederationID = "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" - } - - done := make(chan *FedimintClient) - go func() { - fc := NewFedimintClient(baseURL, password, activeFederationID) - fc.UseDefaultGateway() - done <- fc - }() - return <-done -} - -func TestFedimintGo(t *testing.T) { - fc := CreateNewFedimintClient() - keyPair := newKeyPair() - fmt.Printf("Generated Key Pair: ") - fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) - fmt.Printf(" Public Key: %s\n", keyPair.PublicKey) - - /////////////////// - // ADMIN METHODS // - /////////////////// - - // `/v2/admin/config` - logMethod("/v2/admin/config") - data, err := fc.Config() - if err != nil { - fmt.Println("Error calling CONFIG: ", err) - return - } - logInputAndOutput(nil, data) - - // `/v2/admin/discover-version` - logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) - if err != nil { - fmt.Println("Error calling VERSION: ", err) - return - } - logInputAndOutput(1, data) - - // `/v2/admin/federation-ids - logMethod("/v2/admin/federation-ids") - federationIds, err := fc.FederationIds() - if err != nil { - fmt.Println("Error calling FEDERATION_IDS: ", err) - return - } - logInputAndOutput(nil, federationIds) - - // `/v2/admin/info` - logMethod("/v2/admin/info") - infoData, err := fc.Info() - if err != nil { - fmt.Println("Error calling INFO: ", err) - return - } - logInputAndOutput(nil, infoData) - - // `/v2/admin/join` - inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") - if inviteCode == "" { - inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" - } - logMethod("/v2/admin/join") - joinData, err := fc.Join(inviteCode, true, true, false) - if err != nil { - fmt.Println("Error calling JOIN: ", err) - return - } - logInputAndOutput(inviteCode, joinData) - - // `/v2/admin/list-operations` - logMethod("/v2/admin/list-operations") - listOperationsData, err := fc.ListOperations(10, nil) - if err != nil { - fmt.Println("Error calling JOIN: ", err) - return - } - logInputAndOutput([]interface{}{10}, listOperationsData) - - /////////////////////// - // LIGHTNING METHODS // - /////////////////////// - - // `/v2/ln/list-gateways` - gatewayList, err := fc.Ln.ListGateways() - if err != nil { - fmt.Println("Error calling LIST_GATEWAYS: ", err) - return - } - logInputAndOutput(nil, gatewayList) - - // `/v2/ln/invoice` - logMethod("/v2/ln/invoice") - invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) - if err != nil { - fmt.Println("Error calling INVOICE: ", err) - return - } - logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) - - // `/v2/ln/pay` - logMethod("/v2/ln/pay") - payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) - if err != nil { - fmt.Println("Error calling PAY: ", err) - return - } - logInputAndOutput(invoiceData.Invoice, payData) - - // /v2/ln/await-invoice - logMethod("/v2/ln/await-invoice") - awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) - if err != nil { - fmt.Println("Error calling AWAIT_INVOICE: ", err) - return - } - logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) - - // `/v1/ln/invoice-external-pubkey-tweaked` - logMethod("/v1/ln/invoice-external-pubkey-tweaked") - tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) - if err != nil { - fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) - - // `/v1/ln/claim-external-pubkey-tweaked` - logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, nil) - if err != nil { - fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) - - // `/v1/ln/invoice-external-pubkey` - logMethod("/v1/ln/invoice-external-pubkey") - invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) - if err != nil { - fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) - - // `/v1/ln/claim-external-pubkey-tweaked` - logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) - if err != nil { - fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) - - ////////////////// - // MINT METHODS // - ////////////////// - - // `/v2/mint/spend` - logMethod("/v2/mint/spend") - mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) - if err != nil { - fmt.Println("Error calling SPEND: ", err) - return - } - logInputAndOutput([]interface{}{3000, true, 1000}, mintData) - - // `/v2/mint/decode-notes` - logMethod("/v2/mint/decode-notes") - decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling DECODE_NOTES: ", err) - return - } - logInputAndOutput(mintData.Notes, decodedData) - - // `/v2/mint/encode-notes` - logMethod("/v2/mint/encode-notes") - encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) - if err != nil { - fmt.Println("Error calling DECODE_NOTES: ", err) - return - } - logInputAndOutput(decodedData.NotesJson, encodedData) - - // `/v2/mint/validate` - logMethod("/v2/mint/validate") - validateData, err := fc.Mint.Validate(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling VALIDATE: ", err) - return - } - logInputAndOutput(mintData.Notes, validateData) - - // `/v2/mint/reissue` - logMethod("/v2/mint/reissue") - reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling REISSUE: ", err) - return - } - logInputAndOutput(mintData.Notes, reissueData) - - // `/v2/mint/split` - logMethod("/v2/mint/split") - splitData, err := fc.Mint.Split(mintData.Notes) - if err != nil { - fmt.Println("Error calling SPLIT: ", err) - return - } - logInputAndOutput(mintData.Notes, splitData) - - // `/v2/mint/combine` - logMethod("/v2/mint/combine") - notesVec := func() []string { - result := make([]string, 0, len(splitData.Notes)) - for _, value := range splitData.Notes { - result = append(result, value) - } - return result - }() - combineData, err := fc.Mint.Combine(notesVec) - if err != nil { - fmt.Println("Error calling COMBINE: ", err) - return - } - logInputAndOutput(splitData.Notes, combineData) - - ///////////////////// - // ONCHAIN METHODS // - ///////////////////// - - // `/v2/onchain/deposit-address` - logMethod("/v2/onchain/deposit-address") - addr, err := fc.Onchain.createDepositAddress(1000, nil) - if err != nil { - fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) - return - } - logInputAndOutput(1000, addr) - - // `/v2/onchain/withdraw` - logMethod("/v2/onchain/withdraw") - withdrawData, err := fc.Onchain.withdraw(addr.Address, 1000, nil) - if err != nil { - fmt.Println("Error calling WITHDRAW: ", err) - return - } - logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) - - // `/v2/onchain/await-deposit` - logMethod("/v2/onchain/await-deposit") - awaitDepositData, err := fc.Onchain.awaitDeposit(addr.OperationId, nil) - if err != nil { - fmt.Println("Error calling AWAIT_DEPOSIT: ", err) - return - } - logInputAndOutput(addr.Address, awaitDepositData) -} - -// func TestNewFedimintClient(t *testing.T) { -// fc := CreateNewFedimintClient() -// assert.NotNil(t, fc) - -// assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") -// assert.Equal(t, fc.Password, "password") -// assert.Equal(t, fc.ActiveFederationId, "federation123") - -// assert.Equal(t, fc, fc.Ln.Client) -// assert.Equal(t, fc, fc.Onchain.Client) -// assert.Equal(t, fc, fc.Mint.Client) -// } - -// func TestGetActiveFederationId(t *testing.T) { -// fc := CreateNewFedimintClient() - -// fedId := fc.GetActiveFederationId() -// assert.Equal(t, fedId, "federation123") -// } - -// func TestSetActiveFederationId(t *testing.T) { -// fc := CreateNewFedimintClient() -// new_fedId := "New_federation123" - -// fedId_prev := fc.ActiveFederationId -// fc.SetActiveFederationId(new_fedId, false) -// fedId_now := fc.ActiveFederationId -// assert.Equal(t, fedId_now, "New_federation123") -// assert.NotEqual(t, fedId_now, fedId_prev) -// } - -// //////////// -// // Onchain // -// //////////// - -// func TestCreateDepositAddress(t *testing.T) { -// fc := CreateNewFedimintClient() - -// depositAddressRequest := modules.OnchainDepositAddressRequest{ -// Timeout: 3600, -// } - -// depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, depositResponse, nil) -// assert.Equal(t, depositResponse.OperationId, nil) -// assert.Equal(t, depositResponse.Address, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, depositResponse.OperationId, nil) -// assert.NotEqual(t, depositResponse.Address, nil) -// } - -// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ -// OperationId: depositResponse.OperationId, -// } - -// _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// fmt.Println("Error awaiting deposit: ", err) -// return -// } -// } - -// func TestWithdraw(t *testing.T) { -// fc := CreateNewFedimintClient() - -// withdrawRequest := modules.OnchainWithdrawRequest{ -// Address: "UNKNOWN", -// AmountSat: 10000, -// } - -// withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) - -// assert.NotEqual(t, withdrawResponse, nil) - -// // Intentionally make an error (like - wrong ActiveFederationId/request) -// wrong_fed_id := "12112" -// _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) -// assert.NotEqual(t, err, nil) -// } - -// func TestAwaitWithdraw(t *testing.T) { -// fc := CreateNewFedimintClient() - -// depositAddressRequest := modules.OnchainDepositAddressRequest{ -// Timeout: 3600, -// } -// depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) - -// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ -// OperationId: depositResponse.OperationId, -// } - -// awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, awaitDepositResponse, nil) -// assert.Equal(t, awaitDepositResponse.Status, nil) -// } else { -// assert.Equal(t, err, nil) -// // println(awaitDepositResponse.Status) -// assert.NotEqual(t, awaitDepositResponse.Status, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// ////////// -// // mint // -// ////////// - -// // func TestReissue(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // oobNotesData := modules.OOBNotes { - -// // } -// // } - -// func TestSpend(t *testing.T) { -// fc := CreateNewFedimintClient() - -// spendRequest := modules.MintSpendRequest{ -// AmountMsat: 10000, -// AllowOverpay: true, -// Timeout: 3600, -// } - -// spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, spendResponse, nil) -// assert.Equal(t, spendResponse.OperationId, nil) -// assert.Equal(t, spendResponse.Notes, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, spendResponse, nil) -// assert.NotEqual(t, spendResponse.OperationId, nil) -// assert.NotEqual(t, spendResponse.Notes, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// // func TestValidate(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // } - -// //////// -// // Ln // -// //////// - -// func TestCreateInvoice(t *testing.T) { -// fc := CreateNewFedimintClient() - -// expiryTime := 3600 -// GatewayID := "test_GatewayID" -// invoiceRequest := modules.LnInvoiceRequest{ -// AmountMsat: 10000, -// Description: "test", -// ExpiryTime: &expiryTime, -// } - -// invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, invoiceResponse, nil) -// assert.Equal(t, invoiceResponse.OperationId, nil) -// assert.Equal(t, invoiceResponse.Invoice, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, invoiceResponse, nil) -// assert.NotEqual(t, invoiceResponse.OperationId, nil) -// assert.NotEqual(t, invoiceResponse.Invoice, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// func TestAwaitInvoice(t *testing.T) { -// fc := CreateNewFedimintClient() - -// awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ -// OperationId: "TestAwaitInvoice", -// } - -// infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, infoResponse, nil) -// assert.Equal(t, infoResponse.DenominationsMsat, nil) -// assert.Equal(t, infoResponse.FederationID, nil) -// assert.Equal(t, infoResponse.Meta, nil) -// assert.Equal(t, infoResponse.Network, nil) -// assert.Equal(t, infoResponse.TotalAmountMsat, nil) -// assert.Equal(t, infoResponse.TotalNumNotes, nil) -// assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) -// assert.NotEqual(t, infoResponse, nil) -// assert.NotEqual(t, infoResponse.Meta, nil) -// assert.NotEqual(t, infoResponse.Network, nil) -// assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) -// assert.NotEqual(t, infoResponse.TotalNumNotes, nil) -// assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "" -// _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// func TestPay(t *testing.T) { -// fc := CreateNewFedimintClient() - -// LnurlComment := "test_LnurlComment" -// GatewayID := "test_GatewayID" -// AmountMsat := uint64(10000) -// lnPayRequest := modules.LnPayRequest{ -// PaymentInfo: "TestPayment", -// AmountMsat: &AmountMsat, -// LnurlComment: &LnurlComment, -// } - -// lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, lnPayResponse, nil) -// assert.Equal(t, lnPayResponse.ContractId, nil) -// assert.Equal(t, lnPayResponse.Fee, nil) -// assert.Equal(t, lnPayResponse.PaymentType, nil) -// assert.Equal(t, lnPayResponse.PperationId, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, lnPayResponse, nil) -// assert.NotEqual(t, lnPayResponse.ContractId, nil) -// assert.NotEqual(t, lnPayResponse.Fee, nil) -// assert.NotEqual(t, lnPayResponse.PaymentType, nil) -// assert.NotEqual(t, lnPayResponse.PperationId, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// // func TestAwaitPay(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // awaitLnPayRequest := modules.AwaitLnPayRequest{ -// // OperationId: "TestAwaitLnPay", -// // } - -// // lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) -// // if err != nil { -// // assert.Equal(t, lnPayResponse, nil) -// // assert.Equal(t, lnPayResponse.Contract_id, nil) -// // assert.Equal(t, lnPayResponse.Fee, nil) -// // assert.Equal(t, lnPayResponse.Payment_type, nil) -// // assert.Equal(t, lnPayResponse.Pperation_id, nil) -// // } else { -// // assert.Equal(t, err, nil) -// // assert.NotEqual(t, lnPayResponse, nil) -// // assert.NotEqual(t, lnPayResponse.Contract_id, nil) -// // assert.NotEqual(t, lnPayResponse.Fee, nil) -// // assert.NotEqual(t, lnPayResponse.Payment_type, nil) -// // assert.NotEqual(t, lnPayResponse.Pperation_id, nil) -// // } - -// // // intentionally giving wrong parameters -// // wrong_fed_id := "12112" -// // _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) -// // assert.NotEqual(t, err1, nil) -// // } - -// func TestListGateways(t *testing.T) { -// fc := CreateNewFedimintClient() - -// gatewaysResponse, err := fc.Ln.ListGateways() -// if err != nil { -// assert.Equal(t, gatewaysResponse, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, gatewaysResponse, nil) -// } -// } - -// func TestSwitchGateway(t *testing.T) { -// fc := CreateNewFedimintClient() - -// switchGatewayRequest := modules.SwitchGatewayRequest{ -// GatewayId: "TestGateway1", -// } - -// gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, gatewayResponse, nil) -// assert.Equal(t, gatewayResponse.Active, true) -// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.Equal(t, gatewayResponse.Active, true) -// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } From dae92beb454d302739f538590c2c70800cae7d4e Mon Sep 17 00:00:00 2001 From: yemmyharry Date: Mon, 15 Apr 2024 06:03:02 +0100 Subject: [PATCH 20/23] fix: refactor code --- wrappers/fedimint-go/pkg/fedimint/client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 8aaf3ff..9b97c2a 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -124,12 +124,12 @@ func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{} } // Initialize and convert JSON to map for manipulation - var bodyMap map[string]interface{} = make(map[string]interface{}) // Initialize the map here + var bodyMap = make(map[string]interface{}) // Initialize the map here if err := json.Unmarshal(bodyJSON, &bodyMap); err != nil { return nil, err } - // If bodyMap is nil after unmarshaling, initialize it + // If bodyMap is nil after unmarshalling, initialize it if bodyMap == nil { println("bodyMap is nil") bodyMap = make(map[string]interface{}) @@ -294,7 +294,7 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us func (onchain *OnchainModule) CreateDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { request := modules.OnchainDepositAddressRequest{Timeout: timeout} - resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, federationId) + resp, err := onchain.Client.postWithFederationId("/wallet/deposit-address", request, federationId) if err != nil { return nil, err } @@ -308,7 +308,7 @@ func (onchain *OnchainModule) CreateDepositAddress(timeout int, federationId *st func (onchain *OnchainModule) AwaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { request := modules.OnchainAwaitDepositRequest{OperationId: operationId} - resp, err := onchain.Client.postWithFederationId("/onchain/await-deposit", request, federationId) + resp, err := onchain.Client.postWithFederationId("/wallet/await-deposit", request, federationId) if err != nil { return nil, err } @@ -322,7 +322,7 @@ func (onchain *OnchainModule) AwaitDeposit(operationId string, federationId *str func (onchain *OnchainModule) Withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { request := modules.OnchainWithdrawRequest{Address: address, AmountSat: amountSat} - resp, err := onchain.Client.postWithFederationId("/onchain/withdraw", request, federationId) + resp, err := onchain.Client.postWithFederationId("/wallet/withdraw", request, federationId) if err != nil { return nil, err } From 8994f545c2c1817421b2e4cc0f7761dad862c4ac Mon Sep 17 00:00:00 2001 From: yemmyharry Date: Mon, 15 Apr 2024 06:04:33 +0100 Subject: [PATCH 21/23] fix: refactor code --- wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go index 2f1466c..e4fa3f7 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go @@ -46,7 +46,7 @@ type LnPayRequest struct { } type LnPayResponse struct { - PperationId string `json:"operationId"` + OperationId string `json:"operationId"` PaymentType string `json:"paymentType"` ContractId string `json:"contractId"` Fee int `json:"fee"` From 3bf0f44f58de613ba58146d4b9664fa9c411cd17 Mon Sep 17 00:00:00 2001 From: yemmyharry Date: Mon, 15 Apr 2024 06:28:16 +0100 Subject: [PATCH 22/23] fix: refactor code --- wrappers/fedimint-go/cmd/main.go | 84 ++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 5037003..c690909 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -100,7 +100,7 @@ func main() { var fedimintResponseData interface{} err = json.Unmarshal(jsonBytes, &fedimintResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(discover-version):", err) + fmt.Println("Error unmarshalling JSON(discover-version):", err) return } @@ -131,7 +131,7 @@ func main() { var infoResponseData interface{} err = json.Unmarshal(jsonBytes, &infoResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(discover-version):", err) + fmt.Println("Error unmarshalling JSON(discover-version):", err) return } @@ -157,7 +157,7 @@ func main() { var joinResponseData interface{} err = json.Unmarshal(jsonBytes, &joinResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(join):", err) + fmt.Println("Error unmarshalling JSON(join):", err) return } @@ -179,7 +179,7 @@ func main() { var listOperationsResponseData interface{} err = json.Unmarshal(jsonBytes, &listOperationsResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(list-operations):", err) + fmt.Println("Error unmarshalling JSON(list-operations):", err) return } @@ -205,7 +205,7 @@ func main() { var gatewayListResponseData interface{} err = json.Unmarshal(jsonBytes, &gatewayListResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(list-gateways):", err) + fmt.Println("Error unmarshalling JSON(list-gateways):", err) return } @@ -213,7 +213,8 @@ func main() { // `/v2/ln/invoice` logMethod("/v2/ln/invoice") - invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) + gatewayId := "035f2f7912e0f570841d5c0d8976a40af0dcca5609198436f596e78d2c851ee58a" + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, &gatewayId, nil) if err != nil { fmt.Println("Error calling INVOICE: ", err) return @@ -227,7 +228,7 @@ func main() { var invoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &invoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(invoice):", err) + fmt.Println("Error unmarshalling JSON(invoice):", err) return } @@ -235,7 +236,11 @@ func main() { // `/v2/ln/pay` logMethod("/v2/ln/pay") - payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + comment := "Test for services" + if invoiceData == nil { + fmt.Println("invoice data is empty") + } + payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, &comment, &gatewayId, nil) if err != nil { fmt.Println("Error calling PAY: ", err) return @@ -249,7 +254,7 @@ func main() { var payResponseData interface{} err = json.Unmarshal(jsonBytes, &payResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(pay):", err) + fmt.Println("Error unmarshalling JSON(pay):", err) return } @@ -257,6 +262,9 @@ func main() { // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") + if invoiceData == nil { + fmt.Println("invoice data is empty") + } awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) if err != nil { fmt.Println("Error calling AWAIT_INVOICE: ", err) @@ -271,7 +279,7 @@ func main() { var awaitInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &awaitInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(await-invoice):", err) + fmt.Println("Error unmarshalling JSON(await-invoice):", err) return } @@ -279,7 +287,7 @@ func main() { // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked") - tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, &gatewayId, nil) if err != nil { fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) return @@ -293,7 +301,7 @@ func main() { var tweakInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &tweakInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(await-invoice):", err) + fmt.Println("Error unmarshalling JSON(await-invoice):", err) return } @@ -318,7 +326,7 @@ func main() { var claimInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &claimInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(claim-external-pubkey-tweaked):", err) + fmt.Println("Error unmarshalling JSON(claim-external-pubkey-tweaked):", err) return } @@ -344,7 +352,7 @@ func main() { var mintResponseData interface{} err = json.Unmarshal(jsonBytes, &mintResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(spend):", err) + fmt.Println("Error unmarshalling JSON(spend):", err) return } @@ -352,6 +360,10 @@ func main() { // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } decodedData, err := fc.Mint.DecodeNotes(mintData.Notes) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) @@ -366,7 +378,7 @@ func main() { var decodedResponseData interface{} err = json.Unmarshal(jsonBytes, &decodedResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(decode-notes):", err) + fmt.Println("Error unmarshalling JSON(decode-notes):", err) return } @@ -374,9 +386,13 @@ func main() { // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") + if decodedData == nil { + fmt.Println("decodedData is nil.") + return + } encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson) if err != nil { - fmt.Println("Error calling DECODE_NOTES: ", err) + fmt.Println("Error calling ENCODE_NOTES: ", err) return } @@ -388,7 +404,7 @@ func main() { var encodedResponseData interface{} err = json.Unmarshal(jsonBytes, &encodedResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(encode-notes):", err) + fmt.Println("Error unmarshalling JSON(encode-notes):", err) return } @@ -396,6 +412,10 @@ func main() { // `/v2/mint/validate` logMethod("/v2/mint/validate") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } validateData, err := fc.Mint.Validate(mintData.Notes, nil) if err != nil { fmt.Println("Error calling VALIDATE: ", err) @@ -410,7 +430,7 @@ func main() { var validateResponseData interface{} err = json.Unmarshal(jsonBytes, &validateResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(validate):", err) + fmt.Println("Error unmarshalling JSON(validate):", err) return } @@ -418,6 +438,10 @@ func main() { // `/v2/mint/reissue` logMethod("/v2/mint/reissue") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) if err != nil { fmt.Println("Error calling REISSUE: ", err) @@ -432,7 +456,7 @@ func main() { var reissueResponseData interface{} err = json.Unmarshal(jsonBytes, &reissueResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(reissue):", err) + fmt.Println("Error unmarshalling JSON(reissue):", err) return } @@ -440,6 +464,10 @@ func main() { // `/v2/mint/split` logMethod("/v2/mint/split") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } splitData, err := fc.Mint.Split(mintData.Notes) if err != nil { fmt.Println("Error calling SPLIT: ", err) @@ -454,7 +482,7 @@ func main() { var splitResponseData interface{} err = json.Unmarshal(jsonBytes, &splitResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(split):", err) + fmt.Println("Error unmarshalling JSON(split):", err) return } @@ -463,6 +491,10 @@ func main() { // `/v2/mint/combine` logMethod("/v2/mint/combine") notesVec := func() []string { + if splitData == nil || splitData.Notes == nil { + fmt.Println("splitData or splitData.Notes is nil") + return nil + } result := make([]string, 0, len(splitData.Notes)) for _, value := range splitData.Notes { result = append(result, value) @@ -477,13 +509,13 @@ func main() { jsonBytes, err = json.Marshal(combineData) if err != nil { - fmt.Println("Error marshaling JSON(split):", err) + fmt.Println("Error marshaling JSON(combine-data):", err) return } var combineResponseData interface{} err = json.Unmarshal(jsonBytes, &combineResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(split):", err) + fmt.Println("Error unmarshalling JSON(combine-data):", err) return } @@ -494,7 +526,7 @@ func main() { ///////////////////// // `/v2/onchain/deposit-address` - logMethod("/v2/onchain/deposit-address") + logMethod("/v2/wallet/deposit-address") addr, err := fc.Onchain.CreateDepositAddress(1000, nil) if err != nil { fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) @@ -509,14 +541,14 @@ func main() { var addrResponseData interface{} err = json.Unmarshal(jsonBytes, &addrResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(deposit-address):", err) + fmt.Println("Error unmarshalling JSON(deposit-address):", err) return } logInputAndOutput(1000, addrResponseData) // `/v2/onchain/withdraw` - logMethod("/v2/onchain/withdraw") + logMethod("/v2/wallet/withdraw") withdrawData, err := fc.Onchain.Withdraw(addr.Address, 1000, nil) if err != nil { fmt.Println("Error calling WITHDRAW: ", err) @@ -531,7 +563,7 @@ func main() { var withdrawResponseData interface{} err = json.Unmarshal(jsonBytes, &withdrawResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(withdraw):", err) + fmt.Println("Error unmarshalling JSON(withdraw):", err) return } From c212a0a05c298340b48ea459e340cc1052b93681 Mon Sep 17 00:00:00 2001 From: yemmyharry Date: Mon, 15 Apr 2024 06:30:12 +0100 Subject: [PATCH 23/23] ignore .idea files --- wrappers/fedimint-go/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/wrappers/fedimint-go/.gitignore b/wrappers/fedimint-go/.gitignore index 4c49bd7..e58e5a2 100644 --- a/wrappers/fedimint-go/.gitignore +++ b/wrappers/fedimint-go/.gitignore @@ -1 +1,2 @@ .env +.idea