package disperse import ( "chain" "chain/banker" "strings" "testing" "gno.land/p/nt/testutils/v0" "gno.land/p/nym-smelt001/solrt" ) func TestDisperseCSV(cur realm, t *testing.T) { sender := testutils.TestAddress("sender_csv") alice := testutils.TestAddress("alice_csv") bob := testutils.TestAddress("bob_csv") testing.SetRealm(testing.NewUserRealm(sender)) testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 2000))) realmAddr := chain.PackageAddress("gno.land/r/nym-smelt001/disperse") testing.IssueCoins(realmAddr, chain.NewCoins(chain.NewCoin("ugnot", 2000))) DisperseCSV(cross(cur), string(alice)+", "+string(bob), 1000) ro := banker.NewReadonlyBanker() if got := ro.GetCoin(alice, "ugnot"); got != 1000 { t.Fatalf("alice expected 1000 ugnot, got %d", got) } if got := ro.GetCoin(bob, "ugnot"); got != 1000 { t.Fatalf("bob expected 1000 ugnot, got %d", got) } rendered := Render("") if !strings.Contains(rendered, "Smelt BatchDisperse") || !strings.Contains(rendered, "DisperseCSV") { t.Fatalf("unexpected Render output:\n%s", rendered) } } func TestDisperseNativeU256(cur realm, t *testing.T) { sender := testutils.TestAddress("sender_native") alice := testutils.TestAddress("alice_native") bob := testutils.TestAddress("bob_native") testing.SetRealm(testing.NewUserRealm(sender)) testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 3000))) realmAddr := chain.PackageAddress("gno.land/r/nym-smelt001/disperse") testing.IssueCoins(realmAddr, chain.NewCoins(chain.NewCoin("ugnot", 3000))) DisperseNative( cross(cur), []address{alice, bob}, []solrt.U256{solrt.U256FromU64(1200), solrt.U256FromU64(1800)}, ) ro := banker.NewReadonlyBanker() if got := ro.GetCoin(alice, "ugnot"); got != 1200 { t.Fatalf("alice expected 1200 ugnot, got %d", got) } if got := ro.GetCoin(bob, "ugnot"); got != 1800 { t.Fatalf("bob expected 1800 ugnot, got %d", got) } batches, recipients, _ := Stats() if batches == 0 || recipients < 2 { t.Fatalf("expected updated stats, got batches=%d recipients=%d", batches, recipients) } } func TestDisperseRejectsValueMismatch(cur realm, t *testing.T) { sender := testutils.TestAddress("sender_bad") alice := testutils.TestAddress("alice_bad") testing.SetRealm(testing.NewUserRealm(sender)) testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 500))) r := revive(func() { DisperseNative(cross(cur), []address{alice}, []solrt.U256{solrt.U256FromU64(1000)}) }) if r == nil { t.Fatalf("expected ValueMismatch panic when attached ugnot != sum") } }