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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package transactions
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/algorand/go-algorand/test/framework/fixtures"
"github.com/algorand/go-algorand/test/partitiontest"
)
func TestAccountsCanClose(t *testing.T) {
partitiontest.PartitionTest(t)
defer fixtures.ShutdownSynchronizedTest(t)
t.Parallel()
a := require.New(fixtures.SynchronizedTest(t))
var fixture fixtures.RestClientFixture
fixture.Setup(t, filepath.Join("nettemplates", "TwoNodes50EachV15.json"))
defer fixture.Shutdown()
client := fixture.LibGoalClient
// We will create three new accounts, transfer some amount of money into
// the first account, and then transfer a smaller amount to the second
// account while closing out the rest into the third.
accountList, err := fixture.GetWalletsSortedByBalance()
a.NoError(err)
baseAcct := accountList[0].Address
walletHandle, err := client.GetUnencryptedWalletHandle()
a.NoError(err)
acct0, err := client.GenerateAddress(walletHandle)
a.NoError(err)
acct1, err := client.GenerateAddress(walletHandle)
a.NoError(err)
acct2, err := client.GenerateAddress(walletHandle)
a.NoError(err)
status, err := client.Status()
a.NoError(err)
// Transfer some money to acct0 and wait.
tx, err := client.SendPaymentFromUnencryptedWallet(baseAcct, acct0, 1000, 10000000, nil)
a.NoError(err)
fixture.WaitForConfirmedTxn(status.LastRound+10, baseAcct, tx.ID().String())
tx, err = client.SendPaymentFromWallet(walletHandle, nil, acct0, acct1, 1000, 1000000, nil, acct2, 0, 0)
a.NoError(err)
fixture.WaitForConfirmedTxn(status.LastRound+10, acct0, tx.ID().String())
bal0, err := client.GetBalance(acct0)
a.NoError(err)
bal1, err := client.GetBalance(acct1)
a.NoError(err)
bal2, err := client.GetBalance(acct2)
a.NoError(err)
a.True(bal0 == 0)
a.True(bal1 >= 1000000)
a.True(bal2 >= 8999000)
}
|