a_test.go (2535B)
1 package main 2 3 import ( 4 "encoding/base64" 5 "fmt" 6 "testing" 7 "time" 8 ) 9 10 func Test(t *testing.T) { 11 12 base64encoded := "li0v/6Si7cqmH3z3L62IYCqCxvQlw2Xijw469zzqdZQ=" 13 bytes, _ := base64.StdEncoding.DecodeString(base64encoded) 14 crockencoded := encodeCrock(bytes) 15 decoded, _ := decodeCrock(crockencoded) 16 17 fmt.Println("HEX:", fmt.Sprintf("%x", bytes)) 18 fmt.Println("BASE64:", base64encoded) 19 fmt.Println("CROCK:", crockencoded) 20 fmt.Println("HEX:", fmt.Sprintf("%x", decoded)) 21 } 22 23 func Test2(t *testing.T) { 24 25 wopid := "JRPJZZX4MBPWN9GZFKVJZBC8C0N85HQM4Q1PBRMF1RXFEF7AEPA0" 26 27 awaitSelection := make(chan *BankWithdrawalOperationStatus) 28 29 fmt.Println("TERMINAL: now sending long poll request to c2ec from terminal and await parameter selection") 30 go func() { 31 32 url := FormatUrl( 33 "http://taler-c2ec.ti.bfh.ch/withdrawals/:wopid", 34 map[string]string{"wopid": wopid}, 35 map[string]string{"long_poll_ms": "10000"}, 36 ) 37 fmt.Println("TERMINAL: requesting status update for withdrawal", url) 38 response, status, err := HttpGet( 39 url, 40 map[string]string{"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", "Simulation-1", "")))}, 41 NewJsonCodec[BankWithdrawalOperationStatus](), 42 ) 43 if err != nil { 44 fmt.Println(err.Error()) 45 return 46 } 47 if status != 200 { 48 fmt.Println("long poll failed") 49 return 50 } 51 52 awaitSelection <- response 53 }() 54 55 var C2EC_BANK_WITHDRAWAL_REGISTRATION_URL = "http://taler-c2ec.ti.bfh.ch/taler-integration/withdrawal-operation/:wopid" 56 57 registrationUrl := FormatUrl( 58 C2EC_BANK_WITHDRAWAL_REGISTRATION_URL, 59 map[string]string{"wopid": wopid}, 60 map[string]string{}, 61 ) 62 63 reg := new(BankWithdrawalOperationPostRequest) 64 reg.ReservePubKey = EddsaPublicKey(simulateReservePublicKey()) 65 reg.Amount = nil 66 reg.SelectedExchange = C2EC_BANK_BASE_URL 67 68 time.Sleep(time.Duration(5000) * time.Millisecond) 69 70 res, status, err := HttpPost( 71 registrationUrl, 72 map[string]string{ 73 "Authorization": "application/json", 74 }, 75 reg, 76 NewJsonCodec[BankWithdrawalOperationPostRequest](), 77 NewJsonCodec[BankWithdrawalOperationPostResponse](), 78 //cdc.HttpApplicationContentHeader(), 79 //bytes.NewReader(regByte.Bytes()), 80 ) 81 82 if err != nil { 83 fmt.Println("WALLET : error on POST request:", err.Error()) 84 } 85 86 if status != 200 { 87 fmt.Println("WALLET : response status from registration:", status) 88 } 89 90 fmt.Println(res.ConfirmTransferUrl, res.Status, res.TransferDone) 91 92 for r := range awaitSelection { 93 fmt.Println("selected parameters:", r.ReservePubKey, r.Status) 94 } 95 }