|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + "gno.land/r/demo/gov" |
| 8 | +) |
| 9 | + |
| 10 | +func main() { |
| 11 | + TestSubmitProposal() |
| 12 | + |
| 13 | + // CANNOT TEST THE FOLLOWING DUE TO THE LACK OF `process` FUNCTION in the integration filetest |
| 14 | + // TestSubmitProposalFailedDeposit() |
| 15 | + // TestSubmitProposalRejected(nil) |
| 16 | + // TestSubmitProposalCommunityPoolSpend(nil) |
| 17 | + // TestSubmitProposalMint(nil) |
| 18 | + // TestProposalParameterChange(nil) |
| 19 | + // TestProposalTally(nil) |
| 20 | +} |
| 21 | + |
| 22 | +func TestSubmitProposal() { |
| 23 | + gov.Init() |
| 24 | + |
| 25 | + id := gov.SubmitProposalText( |
| 26 | + "title", // title |
| 27 | + "summary", // summary |
| 28 | + "metadata", // metadata |
| 29 | + 0, // initial deposit |
| 30 | + ) |
| 31 | + |
| 32 | + now := uint64(time.Now().Unix()) |
| 33 | + |
| 34 | + if id != 1 { |
| 35 | + panic("proposal id should be 1") |
| 36 | + } |
| 37 | + |
| 38 | + proposal := gov.GetProposalById(id) |
| 39 | + |
| 40 | + if proposal.Title != "title" { |
| 41 | + panic("proposal title should be title") |
| 42 | + } |
| 43 | + |
| 44 | + if proposal.Summary != "summary" { |
| 45 | + panic("proposal summary should be summary") |
| 46 | + } |
| 47 | + |
| 48 | + if proposal.Metadata != "metadata" { |
| 49 | + panic("proposal metadata should be metadata") |
| 50 | + } |
| 51 | + |
| 52 | + if proposal.ProposalStatus != gov.ProposalStatusDepositPeriod { |
| 53 | + panic("proposal status should be deposit period") |
| 54 | + } |
| 55 | + |
| 56 | + if proposal.SubmitTime != now { |
| 57 | + panic("proposal submit time should be now") |
| 58 | + } |
| 59 | + |
| 60 | + // 86400 == getDepositPeriod() |
| 61 | + if proposal.DepositEndTime != now+86400 { |
| 62 | + panic(fmt.Sprintf("proposal deposit end time should be now + deposit period, %d, %d", proposal.DepositEndTime, now+86400)) |
| 63 | + } |
| 64 | + |
| 65 | + if proposal.VotingEndTime != 0 { |
| 66 | + panic("proposal voting end time should be 0") |
| 67 | + } |
| 68 | + |
| 69 | + if proposal.TotalDeposit != 0 { |
| 70 | + panic("proposal total deposits should be 0") |
| 71 | + } |
| 72 | + |
| 73 | + // 10_000_000 == getDepositMinimum() |
| 74 | + // force advance to voting period |
| 75 | + proposal.TotalDeposit = 10_000_000 + 1 |
| 76 | + |
| 77 | + /* |
| 78 | + CAN NOT `process` in the integration filetest |
| 79 | + |
| 80 | + // 86400 == getDepositPeriod() |
| 81 | + if proposal.process(now + 86400 + 1) { |
| 82 | + panic("proposal process should not halt") |
| 83 | + } |
| 84 | + |
| 85 | + // force advance to voting passed |
| 86 | + proposal.YesVotes = 100 |
| 87 | + proposal.NoVotes = 0 |
| 88 | + |
| 89 | + // 259200 == getVotePeriod() |
| 90 | + if proposal.process(now + 86400 + 1 + 259200 + 1) { |
| 91 | + panic("proposal process should not halt") |
| 92 | + } |
| 93 | + */ |
| 94 | +} |
| 95 | + |
| 96 | +// OUTPUT: |
| 97 | +// |
0 commit comments