-
Notifications
You must be signed in to change notification settings - Fork 210
/
provider.go
60 lines (50 loc) · 1.57 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package testutil
import (
"fmt"
"testing"
apptypes "github.com/ovrclk/akash/app/types"
"github.com/ovrclk/akash/state"
"github.com/ovrclk/akash/types"
"github.com/ovrclk/akash/types/base"
"github.com/stretchr/testify/assert"
crypto "github.com/tendermint/go-crypto"
)
func CreateProvider(t *testing.T, app apptypes.Application, account *types.Account, key *crypto.PrivKey, nonce uint64) *types.Provider {
tx := ProviderTx(account, key, nonce)
ctx := apptypes.NewContext(tx)
assert.True(t, app.AcceptTx(ctx, tx.Payload.Payload))
cresp := app.CheckTx(ctx, tx.Payload.Payload)
assert.True(t, cresp.IsOK())
dresp := app.DeliverTx(ctx, tx.Payload.Payload)
assert.Len(t, dresp.Log, 0, fmt.Sprint("Log should be empty but is: ", dresp.Log))
assert.True(t, dresp.IsOK())
return &tx.Payload.GetTxCreateProvider().Provider
}
func ProviderTx(account *types.Account, key *crypto.PrivKey, nonce uint64) *types.Tx {
pubkey := base.PubKey(key.PubKey())
provider := Provider(account.Address, nonce)
return &types.Tx{
Key: &pubkey,
Payload: types.TxPayload{
Payload: &types.TxPayload_TxCreateProvider{
TxCreateProvider: &types.TxCreateProvider{
Provider: *provider,
},
},
},
}
}
func Provider(account base.Bytes, nonce uint64) *types.Provider {
address := state.ProviderAddress(account, nonce)
providerattribute := &types.ProviderAttribute{
Name: "region",
Value: "us-west",
}
attributes := []types.ProviderAttribute{*providerattribute}
provider := &types.Provider{
Address: address,
Attributes: attributes,
Owner: account,
}
return provider
}