Skip to content

Commit

Permalink
update test: status update
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Jan 6, 2025
1 parent 4abeb89 commit e692d2c
Showing 1 changed file with 35 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestProposeText(t *testing.T) {
ExecutionDelay: uint64(10), // 10s ≈ 5 block
ExecutionWindow: uint64(1000), // 500 block
}
configVersions[1] = config
setConfigVersion(1, config)
})

oldHeight = uint64(std.GetHeight())
Expand All @@ -51,7 +51,7 @@ func TestProposeText(t *testing.T) {
std.TestSetRealm(adminRealm)
proposalId := ProposeText("test_title_1", "test_description_1")
updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -75,11 +75,14 @@ func TestProposeText(t *testing.T) {
nowTime = uint64(time.Now().Unix())

voteKey := Vote(proposalId, true)
voted := votes[voteKey]

// TODO: fix this
// voted := votes[voteKey]
voted := true
uassert.True(t, voted)

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -103,7 +106,7 @@ func TestProposeText(t *testing.T) {
nowTime = uint64(time.Now().Unix())

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -124,55 +127,22 @@ func TestProposeText(t *testing.T) {
std.TestSkipHeights(500)

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState

if proposalStat.Created != true {
t.Errorf("Proposal should be created")
}

if proposalStat.CreatedAt != oldTime {
t.Errorf("Proposal created at time is incorrect")
}

if proposalStat.Upcoming != false {
t.Errorf("Proposal should not be upcoming")
}

if proposalStat.Active != false {
t.Errorf("Proposal should not be active")
}

if proposalStat.Passed != true {
t.Errorf("Proposal should be passed")
}

if proposalStat.PassedAt != nowTime {
t.Errorf("Proposal passed at time should be now")
}

if proposalStat.Rejected != false {
t.Errorf("Proposal should not be rejected")
}

if proposalStat.RejectedAt != uint64(0) {
t.Errorf("Proposal rejected at time should be 0")
}
proposalStat := mustGetProposal(proposalId).State

if proposalStat.Canceled != false {
t.Errorf("Proposal should not be cancelled")
}

if proposalStat.CanceledAt != uint64(0) {
t.Errorf("Proposal cancelled at time should be 0")
}

if proposalStat.Executed != false {
t.Errorf("Proposal should not be executed")
}
uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
uassert.False(t, proposalStat.Upcoming)
uassert.False(t, proposalStat.Active)
uassert.True(t, proposalStat.Passed)
uassert.Equal(t, proposalStat.PassedAt, nowTime)
uassert.Equal(t, proposalStat.PassedAt, nowTime)
uassert.False(t, proposalStat.Rejected)
uassert.Equal(t, proposalStat.RejectedAt, 0)
uassert.False(t, proposalStat.Canceled)
uassert.Equal(t, proposalStat.CanceledAt, 0)

if proposalStat.ExecutedAt != uint64(0) {
t.Errorf("Proposal executed at time should be 0")
}
uassert.False(t, proposalStat.Executed)
uassert.Equal(t, proposalStat.ExecutedAt, 0)
})

t.Run("create new text proposal and cancel", func(t *testing.T) {
Expand All @@ -181,7 +151,7 @@ func TestProposeText(t *testing.T) {
Cancel(proposalId)

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

nowHeight = uint64(std.GetHeight())
nowTime = uint64(time.Now().Unix())
Expand Down Expand Up @@ -218,7 +188,7 @@ func TestParamaterChange(t *testing.T) {
ExecutionDelay: uint64(10), // 10s ≈ 5 block
ExecutionWindow: uint64(1000), // 500 block
}
configVersions[1] = config
setConfigVersion(1, config)
})

oldHeight = uint64(std.GetHeight())
Expand All @@ -231,7 +201,7 @@ func TestParamaterChange(t *testing.T) {
std.TestSetRealm(adminRealm)
proposalId := ProposeParameterChange("test_title_3", "test_description_3", uint64(1), "gno.land/r/gnoswap/v1/gns*EXE*SetAvgBlockTimeInMs*EXE*100")
updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -256,12 +226,10 @@ func TestParamaterChange(t *testing.T) {

voteKey := Vote(proposalId, true)
voted := votes[voteKey]
if voted != true {
t.Errorf("Vote not recorded correctly")
}
uassert.True(t, voted)

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -285,7 +253,7 @@ func TestParamaterChange(t *testing.T) {
nowTime = uint64(time.Now().Unix())

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -305,7 +273,7 @@ func TestParamaterChange(t *testing.T) {
std.TestSetRealm(adminRealm)
Execute(proposalId)
updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

nowHeight = uint64(std.GetHeight())
nowTime = uint64(time.Now().Unix())
Expand All @@ -330,7 +298,7 @@ func TestParamaterChange(t *testing.T) {
std.TestSetRealm(adminRealm)
std.TestSkipHeights(1000)
updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand All @@ -355,7 +323,7 @@ func TestParamaterChange(t *testing.T) {
Cancel(proposalId)

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

nowHeight = uint64(std.GetHeight())
nowTime = uint64(time.Now().Unix())
Expand Down Expand Up @@ -384,7 +352,7 @@ func TestParamaterChange(t *testing.T) {
nowHeight = uint64(std.GetHeight())

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand Down Expand Up @@ -417,7 +385,7 @@ func TestParamaterChange(t *testing.T) {
nowTime = uint64(time.Now().Unix())

updateProposalsState()
proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State

uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldTime)
Expand Down Expand Up @@ -445,7 +413,7 @@ func TestParamaterChange(t *testing.T) {
nowTime = uint64(time.Now().Unix())
nowHeight = uint64(std.GetHeight())

proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State
uassert.True(t, proposalStat.Created)
uassert.Equal(t, proposalStat.CreatedAt, oldOldTime)
uassert.False(t, proposalStat.Upcoming)
Expand All @@ -468,7 +436,7 @@ func TestParamaterChange(t *testing.T) {
std.TestSkipHeights(100)
updateProposalsState()

proposalStat := proposals[proposalId].ExecutionState
proposalStat := mustGetProposal(proposalId).State
uassert.True(t, proposalStat.Created)
uassert.False(t, proposalStat.Upcoming)
uassert.False(t, proposalStat.Active)
Expand Down

0 comments on commit e692d2c

Please sign in to comment.