forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
296d1f5
commit a5cef66
Showing
5 changed files
with
131 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package worx | ||
|
||
import ( | ||
"testing" | ||
"gno.land/p/demo/rand" | ||
"gno.land/p/demo/testutils" | ||
"gno.land/p/demo/ufmt" | ||
"std" | ||
) | ||
|
||
func TestAddGet(t *testing.T) { | ||
keeper := NewWorxKeeper() | ||
user1 := testutils.TestAddress("user1") | ||
if len(keeper.Get()) != 0{ | ||
t.Fatalf("Keeper is not empty initialized") | ||
} | ||
|
||
fillRandomWorx(keeper, 10123423, user1) | ||
if len(keeper.Get()) != 1{ | ||
t.Fatalf("Keeper Worx was not added to keeper 1") | ||
} | ||
|
||
fillRandomWorx(keeper, 10123423, user1) | ||
if len(keeper.Get()) != 2{ | ||
t.Fatalf("Keeper Worx was not added to keeper 2") | ||
} | ||
} | ||
|
||
func TestGetFromDate(t *testing.T) { | ||
keeper := NewWorxKeeper() | ||
user1 := testutils.TestAddress("user1") | ||
if len(keeper.Get()) != 0{ | ||
t.Fatalf("Keeper is not empty initialized") | ||
} | ||
|
||
for i:=0; i < 100; i++ { | ||
fillRandomWorx(keeper, int64(i*10), user1) | ||
} | ||
|
||
if len(keeper.Get()) != 100{ | ||
t.Fatalf("Keeper Worx was not totally added") | ||
} | ||
|
||
if len(keeper.GetFromDate(1003)) != 0 { | ||
t.Fatalf("Get From Date Should have found 0 registers") | ||
} | ||
|
||
if len(keeper.GetFromDate(903)) != 9 { | ||
t.Fatalf("Get From Date Should have found 9 registers") | ||
} | ||
|
||
} | ||
|
||
func fillRandomWorx(keeper *WorxKeeper, timestamp int64, address std.Address){ | ||
r := rand.New() | ||
keeper.Store(NewWorx( | ||
r.Intn(25), | ||
"somekey", | ||
address, | ||
r.Intn(100), | ||
timestamp, | ||
)) | ||
} |
22 changes: 22 additions & 0 deletions
22
examples/gno.land/r/demo/teritori/worx_aggregator/admin.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package worx_aggregator | ||
|
||
import ( | ||
"std" | ||
) | ||
|
||
var adminAddr std.Address | ||
|
||
func assertIsAdmin() { | ||
if std.PrevRealm().Addr() != adminAddr { | ||
panic("restricted area") | ||
} | ||
} | ||
|
||
func setAdminAddress(address std.Address) { | ||
adminAddr = address | ||
} | ||
|
||
func SetAdminAddress(address std.Address) { | ||
assertIsAdmin() | ||
setAdminAddress(address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters