commit 43a8938d04511c109b9f5f0197b32017e5ac0f19
parent 37a5ac944335a4c74aad749374f2f4448ca22065
Author: Joel-Haeberli <haebu@rubigen.ch>
Date: Thu, 9 May 2024 12:39:42 +0200
fix: sim issues
Diffstat:
4 files changed, 113 insertions(+), 18 deletions(-)
diff --git a/simulation/a_test.go b/simulation/a_test.go
@@ -0,0 +1,98 @@
+package main
+
+import (
+ "encoding/base64"
+ "fmt"
+ "testing"
+ "time"
+)
+
+func Test(t *testing.T) {
+
+ base64encoded := "li0v/6Si7cqmH3z3L62IYCqCxvQlw2Xijw469zzqdZQ="
+ bytes, _ := base64.StdEncoding.DecodeString(base64encoded)
+ crockencoded := encodeCrock(bytes)
+ decoded, _ := decodeCrock(crockencoded)
+
+ fmt.Println("HEX:", fmt.Sprintf("%x", bytes))
+ fmt.Println("BASE64:", base64encoded)
+ fmt.Println("CROCK:", crockencoded)
+ fmt.Println("HEX:", fmt.Sprintf("%x", decoded))
+}
+
+func Test2(t *testing.T) {
+
+ wopid := "JRPJZZX4MBPWN9GZFKVJZBC8C0N85HQM4Q1PBRMF1RXFEF7AEPA0"
+
+ awaitSelection := make(chan *BankWithdrawalOperationStatus)
+
+ fmt.Println("TERMINAL: now sending long poll request to c2ec from terminal and await parameter selection")
+ go func() {
+
+ url := FormatUrl(
+ "http://taler-c2ec.ti.bfh.ch/withdrawals/:wopid",
+ map[string]string{"wopid": wopid},
+ map[string]string{"long_poll_ms": "10000"},
+ )
+ fmt.Println("TERMINAL: requesting status update for withdrawal", url)
+ response, status, err := HttpGet(
+ url,
+ map[string]string{"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", "Simulation-1", "")))},
+ NewJsonCodec[BankWithdrawalOperationStatus](),
+ )
+ if err != nil {
+ fmt.Println(err.Error())
+ return
+ }
+ if status != 200 {
+ fmt.Println("long poll failed")
+ return
+ }
+
+ awaitSelection <- response
+ }()
+
+ var C2EC_BANK_WITHDRAWAL_REGISTRATION_URL = "http://taler-c2ec.ti.bfh.ch/taler-integration/withdrawal-operation/:wopid"
+
+ registrationUrl := FormatUrl(
+ C2EC_BANK_WITHDRAWAL_REGISTRATION_URL,
+ map[string]string{"wopid": wopid},
+ map[string]string{},
+ )
+
+ reg := new(BankWithdrawalOperationPostRequest)
+ reg.ReservePubKey = EddsaPublicKey(simulateReservePublicKey())
+ reg.Amount = nil
+ reg.SelectedExchange = C2EC_BANK_BASE_URL
+
+ time.Sleep(time.Duration(5000) * time.Millisecond)
+
+ res, status, err := HttpPost(
+ registrationUrl,
+ map[string]string{
+ "Authorization": "application/json",
+ },
+ reg,
+ NewJsonCodec[BankWithdrawalOperationPostRequest](),
+ NewJsonCodec[BankWithdrawalOperationPostResponse](),
+ //cdc.HttpApplicationContentHeader(),
+ //bytes.NewReader(regByte.Bytes()),
+ )
+
+ if err != nil {
+ fmt.Println("WALLET : error on POST request:", err.Error())
+ }
+
+ if status != 200 {
+ fmt.Println("WALLET : response status from registration:", status)
+ }
+
+ fmt.Println(res.ConfirmTransferUrl, res.Status, res.TransferDone)
+
+ for {
+ select {
+ case r := <-awaitSelection:
+ fmt.Println("selected parameters:", r.ReservePubKey, r.Status)
+ }
+ }
+}
diff --git a/simulation/c2ec-simulation b/simulation/c2ec-simulation
Binary files differ.
diff --git a/simulation/sim-wallet.go b/simulation/sim-wallet.go
@@ -1,11 +1,9 @@
package main
import (
- "bytes"
"crypto/rand"
"errors"
"fmt"
- "net/http"
"strconv"
"strings"
"time"
@@ -41,23 +39,22 @@ func Wallet(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysicalIn
map[string]string{},
)
- cdc := NewJsonCodec[BankWithdrawalOperationPostRequest]()
- reg := new(BankWithdrawalOperationPostRequest)
- reg.ReservePubKey = EddsaPublicKey(simulateReservePublicKey())
- reg.Amount = nil
- reg.SelectedExchange = C2EC_BANK_BASE_URL
- body, err := cdc.EncodeToBytes(reg)
- regByte := bytes.NewBuffer(body)
- // fmt.Println("WALLET : body (bytes):", regByte.Bytes())
- if err != nil {
- kill <- err
+ reg := BankWithdrawalOperationPostRequest{
+ ReservePubKey: EddsaPublicKey(simulateReservePublicKey()),
+ Amount: nil,
+ SelectedExchange: C2EC_BANK_BASE_URL,
}
+
fmt.Println("WALLET : wallet sends withdrawal registration request with freshly generated public key.")
fmt.Printf("HTTP : requesting POST %s\n", registrationUrl)
- res, err := http.Post(
+ _, status, err := HttpPost[BankWithdrawalOperationPostRequest, any](
registrationUrl,
- cdc.HttpApplicationContentHeader(),
- bytes.NewReader(regByte.Bytes()),
+ map[string]string{
+ "Authorization": "application/json",
+ },
+ ®,
+ NewJsonCodec[BankWithdrawalOperationPostRequest](),
+ nil,
)
if err != nil {
@@ -65,8 +62,8 @@ func Wallet(in chan *SimulatedPhysicalInteraction, out chan *SimulatedPhysicalIn
kill <- err
}
- if res.StatusCode != 200 {
- fmt.Println("WALLET : response status from registration:", res.StatusCode)
+ if status != 200 {
+ fmt.Println("WALLET : response status from registration:", status)
kill <- errors.New("failed registering the withdrawal parameters")
}
diff --git a/simulation/sim-wire-watch.go b/simulation/sim-wire-watch.go
@@ -25,7 +25,7 @@ func WireWatch(finish chan interface{}, kill chan error) {
wirewatchLongPoll = CONFIG.ProviderBackendPaymentDelay +
CONFIG.TerminalAcceptCardDelay +
CONFIG.WalletScanQrDelay +
- 2000 // add some delay for operations
+ 5000 // add some delay for operations
}
fmt.Println("WIRE-WATCH: long poll to c2ec for ", wirewatchLongPoll, "milliseconds")