Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MYST-18 define client promise #32

Merged
merged 13 commits into from Sep 26, 2017
10 changes: 10 additions & 0 deletions client_promise/dto/promise_body.go
@@ -0,0 +1,10 @@
package dto

import "github.com/mysterium/node/service_discovery/dto"

type PromiseBody struct {
SerialNumber int
IssuerId string
BenefiterId string
Amount dto.Money
}
3 changes: 3 additions & 0 deletions client_promise/dto/signature.go
@@ -0,0 +1,3 @@
package dto

type Signature string
6 changes: 6 additions & 0 deletions client_promise/dto/signed_promise.go
@@ -0,0 +1,6 @@
package dto

type SignedPromise struct {
Promise PromiseBody
IssuerSignature Signature
}
42 changes: 42 additions & 0 deletions client_promise/promise_test.go
@@ -0,0 +1,42 @@
package client_promise

import (
dto "github.com/mysterium/node/client_promise/dto"
discovery_dto "github.com/mysterium/node/service_discovery/dto"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_PromiseBody(t *testing.T) {

amount := discovery_dto.Money{
Amount: uint64(5),
Currency: "Token",
}

promise := dto.PromiseBody{
SerialNumber: 1,
IssuerId: "issuer1",
BenefiterId: "benefiter1",
Amount: amount,
}

assert.Equal(t, promise.SerialNumber, 1)
assert.Equal(t, promise.IssuerId, "issuer1")
assert.Equal(t, promise.BenefiterId, "benefiter1")
assert.Equal(t, promise.Amount.Amount, uint64(5))
assert.Equal(t, promise.Amount.Currency, "Token")
}

func Test_SignedPromise(t *testing.T) {

promise := dto.PromiseBody{}

signedPromise := dto.SignedPromise{
Promise: promise,
IssuerSignature: "signature",
}

assert.Equal(t, signedPromise.Promise, promise)
assert.Equal(t, signedPromise.IssuerSignature, dto.Signature("signature"))
}
4 changes: 2 additions & 2 deletions openvpn/service_discovery/dto/payment_method_per_bytes.go
Expand Up @@ -10,7 +10,7 @@ const PAYMENT_METHOD_PER_BYTES = "PER_BYTES"
type PaymentMethodPerBytes struct {
Type string

Price dto_discovery.Price
Price dto_discovery.Money

// Service bytes provided for paid price
Bytes datasize.BitSize
Expand All @@ -20,6 +20,6 @@ func (method PaymentMethodPerBytes) GetType() string {
return method.Type
}

func (method PaymentMethodPerBytes) GetPrice() dto_discovery.Price {
func (method PaymentMethodPerBytes) GetPrice() dto_discovery.Money {
return method.Price
}
4 changes: 2 additions & 2 deletions openvpn/service_discovery/dto/payment_method_per_time.go
Expand Up @@ -8,12 +8,12 @@ import (
const PAYMENT_METHOD_PER_TIME = "PER_TIME"

type PaymentMethodPerTime struct {
Price dto_discovery.Price
Price dto_discovery.Money

// Service duration provided for paid price
Duration time.Duration
}

func (method PaymentMethodPerTime) GetPrice() dto_discovery.Price {
func (method PaymentMethodPerTime) GetPrice() dto_discovery.Money {
return method.Price
}
2 changes: 1 addition & 1 deletion openvpn/service_discovery/factory.go
Expand Up @@ -20,7 +20,7 @@ func NewServiceProposal(nodeKey string, nodeLocation dto_discovery.Location) dto
PaymentMethodType: dto.PAYMENT_METHOD_PER_TIME,
PaymentMethod: dto.PaymentMethodPerTime{
// 15 MYST/month = 0,5 MYST/day = 0,125 MYST/hour
Price: dto_discovery.Price{0.125, "MYST"},
Price: dto_discovery.Money{0.125, "MYST"},
Duration: 1 * time.Hour,
},
ProviderId: nodeKey,
Expand Down
2 changes: 1 addition & 1 deletion openvpn/service_discovery/factory_test.go
Expand Up @@ -33,7 +33,7 @@ func Test_NewServiceProposal(t *testing.T) {
assert.Equal(
t,
dto.PaymentMethodPerTime{
Price: dto_discovery.Price{0.125, "MYST"},
Price: dto_discovery.Money{0.125, "MYST"},
Duration: 60 * time.Minute,
},
proposal.PaymentMethod,
Expand Down
6 changes: 6 additions & 0 deletions service_discovery/dto/money.go
@@ -0,0 +1,6 @@
package dto

type Money struct {
Amount uint64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests probably broke, check by running bin/test

Currency string
}
2 changes: 1 addition & 1 deletion service_discovery/dto/payment_method.go
Expand Up @@ -2,5 +2,5 @@ package dto

type PaymentMethod interface {
// Service price per unit of metering
GetPrice() Price
GetPrice() Money
}
6 changes: 0 additions & 6 deletions service_discovery/dto/price.go

This file was deleted.