/
organization.go
70 lines (51 loc) · 2.56 KB
/
organization.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
61
62
63
64
65
66
67
68
69
70
package test
import (
"context"
"math/big"
"github.com/valist-io/valist/core/client"
"github.com/valist-io/valist/core/types"
)
func (s *CoreSuite) TestCreateOrganization() {
ctx := context.Background()
orgMeta := &types.OrganizationMeta{
Name: "Valist, Inc.",
Description: "Accelerating the transition to web3.",
}
orgCreatedEvent, err := s.client.CreateOrganization(ctx, orgMeta)
s.Require().NoError(err, "Failed to create organization")
org, err := s.client.GetOrganization(ctx, orgCreatedEvent.OrgID)
s.Require().NoError(err, "Failed to get organization")
s.Assert().Equal(big.NewInt(0).Cmp(org.Threshold), 0)
meta, err := s.client.GetOrganizationMeta(ctx, org.MetaCID)
s.Require().NoError(err, "Failed to get organization meta")
s.Assert().Equal(orgMeta.Name, meta.Name)
s.Assert().Equal(orgMeta.Description, meta.Description)
}
func (s *CoreSuite) TestVoteOrganizationThreshold() {
ctx := context.Background()
orgMeta := &types.OrganizationMeta{
Name: "Valist, Inc.",
Description: "Accelerating the transition to web3.",
}
orgCreatedEvent, err := s.client.CreateOrganization(ctx, orgMeta)
s.Require().NoError(err, "Failed to create organization")
org, err := s.client.GetOrganization(ctx, orgCreatedEvent.OrgID)
s.Require().NoError(err, "Failed to get organization")
s.Assert().Equal(big.NewInt(0).Cmp(org.Threshold), 0)
_, err = s.client.VoteOrganizationThreshold(ctx, orgCreatedEvent.OrgID, big.NewInt(2))
s.Require().Error(err, "Should not be able to vote for threshold without enough members")
_, err = s.client.VoteOrganizationAdmin(ctx, orgCreatedEvent.OrgID, client.ADD_KEY, s.accounts[1].Address)
s.Require().NoError(err, "Failed to add second org admin key")
_, err = s.client.VoteOrganizationAdmin(ctx, orgCreatedEvent.OrgID, client.ADD_KEY, s.accounts[2].Address)
s.Require().NoError(err, "Failed to add third org admin key")
_, err = s.client.VoteOrganizationThreshold(ctx, orgCreatedEvent.OrgID, big.NewInt(2))
s.Require().NoError(err, "Failed to vote for organization threshold")
_, err = s.client.VoteOrganizationThreshold(ctx, orgCreatedEvent.OrgID, big.NewInt(2))
s.Require().Error(err, "Should not be able to vote for threshold again")
s.client.Signer().SetAccount(s.accounts[1])
_, err = s.client.VoteOrganizationThreshold(ctx, orgCreatedEvent.OrgID, big.NewInt(2))
s.Require().NoError(err, "Failed to vote for organization threshold")
org, err = s.client.GetOrganization(ctx, orgCreatedEvent.OrgID)
s.Require().NoError(err, "Failed to get organization")
s.Require().Equal(big.NewInt(2).Cmp(org.Threshold), 0)
}