2023-08-25 15:36:39 +00:00
|
|
|
package communitytokens
|
2023-01-12 15:17:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-21 11:20:43 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/services/wallet/bigint"
|
2023-01-12 15:17:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeploymentParameters(t *testing.T) {
|
|
|
|
var testCases = []struct {
|
|
|
|
name string
|
|
|
|
parameters DeploymentParameters
|
|
|
|
isError bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "emptyName",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"", "SYMBOL", &bigint.BigInt{Int: big.NewInt(int64(123))}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "emptySymbol",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "", &bigint.BigInt{Int: big.NewInt(123)}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negativeSupply",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(-123)}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "zeroSupply",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(0)}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negativeSupplyAndInfinite",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(-123)}, true, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "supplyGreaterThanMax",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(maxSupply + 1)}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "supplyIsMax",
|
2023-07-18 08:33:45 +00:00
|
|
|
parameters: DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(maxSupply)}, false, false, false, "", "", ""},
|
2023-01-12 15:17:21 +00:00
|
|
|
isError: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-06-21 11:20:43 +00:00
|
|
|
err := tc.parameters.Validate(false)
|
2023-01-12 15:17:21 +00:00
|
|
|
if tc.isError {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-18 08:33:45 +00:00
|
|
|
notInfiniteSupplyParams := DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(123)}, false, false, false, "", "", ""}
|
2023-01-12 15:17:21 +00:00
|
|
|
requiredSupply := big.NewInt(123)
|
|
|
|
require.Equal(t, notInfiniteSupplyParams.GetSupply(), requiredSupply)
|
2023-07-18 08:33:45 +00:00
|
|
|
infiniteSupplyParams := DeploymentParameters{"NAME", "SYM", &bigint.BigInt{Int: big.NewInt(123)}, true, false, false, "", "", ""}
|
2023-01-12 15:17:21 +00:00
|
|
|
requiredSupply = infiniteSupplyParams.GetInfiniteSupply()
|
|
|
|
require.Equal(t, infiniteSupplyParams.GetSupply(), requiredSupply)
|
|
|
|
}
|