go: tests for pay and close + makefile
This commit is contained in:
parent
e4e1923419
commit
2b4ad9208f
4
Makefile
4
Makefile
|
@ -42,5 +42,9 @@ cpptests:
|
|||
@LD_LIBRARY_PATH=./target/release/ ./cpp_test
|
||||
@rm cpp_test
|
||||
|
||||
gotests:
|
||||
cargo +nightly build --release
|
||||
go test go/libbolt.go go/libbolt_test.go
|
||||
|
||||
clean:
|
||||
cargo +nightly clean
|
||||
|
|
|
@ -18,6 +18,7 @@ type setupResp struct {
|
|||
ComProof string `json:"com_proof"`
|
||||
IsTokenValid bool `json:"is_token_valid,string"`
|
||||
IsEstablished bool `json:"is_established,string"`
|
||||
IsPayValid bool `json:"is_pay_valid,string"`
|
||||
Payment string `json:"payment"`
|
||||
CloseToken string `json:"close_token"`
|
||||
RevokeToken string `json:"revoke_token"`
|
||||
|
@ -104,7 +105,7 @@ func BidirectionalPayVerifyRevokeToken(serRevokeToken string, serMerchState stri
|
|||
func BidirectionalPayVerifyPaymentToken(serChannelState string, serCustState string, serPayToken string) (string, bool) {
|
||||
resp := C.GoString(C.ffishim_bidirectional_pay_verify_payment_token(C.CString(serChannelState), C.CString(serCustState), C.CString(serPayToken)))
|
||||
r := processCResponse(resp)
|
||||
return r.CustState, r.IsTokenValid
|
||||
return r.CustState, r.IsPayValid
|
||||
}
|
||||
|
||||
func BidirectionalCustomerClose(serChannelState string, serCustState string) string {
|
||||
|
|
|
@ -41,3 +41,42 @@ func Test_Establish(t *testing.T) {
|
|||
assert.True(t, isChannelEstablished)
|
||||
}
|
||||
|
||||
func Test_Pay(t *testing.T) {
|
||||
b0Cust := 1000
|
||||
b0Merch := 100
|
||||
channelState, channelToken, merchState, custState := setup(b0Cust, b0Merch)
|
||||
channelToken, custState, com, comProof := BidirectionalEstablishCustomerGenerateProof(channelToken, custState)
|
||||
closeToken := BidirectionalEstablishMerchantIssueCloseToken(channelState, com, comProof, b0Cust, b0Merch, merchState)
|
||||
_, channelState, custState = BidirectionalVerifyCloseToken(channelState, custState, closeToken)
|
||||
payToken := BidirectionalEstablishMerchantIssuePayToken(channelState, com, merchState)
|
||||
_, channelState, custState = BidirectionalEstablishCustomerFinal(channelState, custState, payToken)
|
||||
|
||||
payment, newCustState := BidirectionalPayGeneratePaymentProof(channelState, custState, 10)
|
||||
closeToken, merchState = BidirectionalPayVerifyPaymentProof(channelState, payment, merchState)
|
||||
revokeToken, custState := BidirectionalPayGenerateRevokeToken(channelState, custState, newCustState, closeToken)
|
||||
payToken, merchState = BidirectionalPayVerifyRevokeToken(revokeToken, merchState)
|
||||
custState, isTokenValid := BidirectionalPayVerifyPaymentToken(channelState, custState, payToken)
|
||||
assert.True(t, isTokenValid)
|
||||
}
|
||||
|
||||
func Test_Close(t *testing.T) {
|
||||
b0Cust := 1000
|
||||
b0Merch := 100
|
||||
channelState, channelToken, merchState, custState := setup(b0Cust, b0Merch)
|
||||
channelToken, custState, com, comProof := BidirectionalEstablishCustomerGenerateProof(channelToken, custState)
|
||||
closeToken := BidirectionalEstablishMerchantIssueCloseToken(channelState, com, comProof, b0Cust, b0Merch, merchState)
|
||||
_, channelState, custState = BidirectionalVerifyCloseToken(channelState, custState, closeToken)
|
||||
payToken := BidirectionalEstablishMerchantIssuePayToken(channelState, com, merchState)
|
||||
_, channelState, custState = BidirectionalEstablishCustomerFinal(channelState, custState, payToken)
|
||||
|
||||
payment, newCustState := BidirectionalPayGeneratePaymentProof(channelState, custState, 10)
|
||||
closeToken, merchState = BidirectionalPayVerifyPaymentProof(channelState, payment, merchState)
|
||||
revokeToken, custState := BidirectionalPayGenerateRevokeToken(channelState, custState, newCustState, closeToken)
|
||||
payToken, merchState = BidirectionalPayVerifyRevokeToken(revokeToken, merchState)
|
||||
custState, _ = BidirectionalPayVerifyPaymentToken(channelState, custState, payToken)
|
||||
|
||||
custClose := BidirectionalCustomerClose(channelState, custState)
|
||||
_, _, err := BidirectionalMerchantClose(channelState, channelToken, "onChainAddress", custClose, merchState)
|
||||
assert.Equal(t, "merchant_close - Could not find entry for wpk & revoke token pair. Valid close!", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ pub mod ffishim {
|
|||
use std::alloc::handle_alloc_error;
|
||||
|
||||
fn error_message(s: String) -> *mut c_char {
|
||||
let ser = ["{\'error\':", serde_json::to_string(&s).unwrap().as_str(), "}"].concat();
|
||||
let ser = ["{\'error\':\'", &s, "\'}"].concat();
|
||||
let cser = CString::new(ser).unwrap();
|
||||
cser.into_raw()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue