github.com/aergoio/aergo@v1.3.1/contract/enterprise/config_test.go (about) 1 package enterprise 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/aergoio/aergo-lib/db" 8 "github.com/aergoio/aergo/state" 9 "github.com/aergoio/aergo/types" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 var cdb *state.ChainStateDB 14 var sdb *state.StateDB 15 16 func initTest(t *testing.T) (*state.ContractState, *state.V, *state.V) { 17 cdb = state.NewChainStateDB() 18 cdb.Init(string(db.BadgerImpl), "test", nil, false) 19 genesis := types.GetTestGenesis() 20 sdb = cdb.OpenNewStateDB(cdb.GetRoot()) 21 err := cdb.SetGenesis(genesis, nil) 22 if err != nil { 23 t.Fatalf("failed init : %s", err.Error()) 24 } 25 const testSender = "AmPNYHyzyh9zweLwDyuoiUuTVCdrdksxkRWDjVJS76WQLExa2Jr4" 26 27 scs, err := cdb.GetStateDB().OpenContractStateAccount(types.ToAccountID([]byte("aergo.system"))) 28 assert.NoError(t, err, "could not open contract state") 29 30 account, err := types.DecodeAddress(testSender) 31 assert.NoError(t, err, "could not decode test address") 32 sender, err := sdb.GetAccountStateV(account) 33 assert.NoError(t, err, "could not get test address state") 34 receiver, err := sdb.GetAccountStateV([]byte(types.AergoEnterprise)) 35 assert.NoError(t, err, "could not get test address state") 36 return scs, sender, receiver 37 } 38 39 func deinitTest() { 40 cdb.Close() 41 os.RemoveAll("test") 42 } 43 44 func TestSetGetConf(t *testing.T) { 45 scs, _, _ := initTest(t) 46 defer deinitTest() 47 testConf := &Conf{On: true, Values: []string{"abc:w", "def:r", "ghi:s"}} 48 retConf, err := getConf(scs, []byte(RPCPermissions)) 49 assert.NoError(t, err, "could not get test conf") 50 assert.Nil(t, retConf, "not set yet") 51 err = setConf(scs, []byte(RPCPermissions), testConf) 52 assert.NoError(t, err, "could not set test conf") 53 retConf, err = getConf(scs, []byte(RPCPermissions)) 54 assert.NoError(t, err, "could not get test conf") 55 assert.Equal(t, testConf.Values, retConf.Values, "check values") 56 assert.Equal(t, testConf.On, retConf.On, "check on") 57 58 testConf2 := &Conf{On: false, Values: []string{"1", "22", "333"}} 59 err = setConf(scs, []byte("p2pwhite"), testConf2) 60 assert.NoError(t, err, "could not set test conf") 61 retConf2, err := getConf(scs, []byte("p2pwhite")) 62 assert.NoError(t, err, "could not get test conf") 63 assert.Equal(t, testConf2.Values, retConf2.Values, "check values") 64 assert.Equal(t, testConf2.On, retConf2.On, "check on") 65 } 66 67 const testCert = `-----BEGIN CERTIFICATE----- 68 MIIE4DCCAsigAwIBAgIBATANBgkqhkiG9w0BAQsFADAQMQ4wDAYDVQQDEwVhZXJn 69 bzAeFw0xOTA1MjIwMTU3MzJaFw0yMDExMjIwMTU3MzJaMBAxDjAMBgNVBAMTBWFl 70 cmdvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA6y/dza6BPg6l//Hv 71 +NR5bgtEVNG68W38vfn/M2WDA9PfIaf2nlH3RiawMpw4G6cT/+qGoESCypDLEASS 72 NUo1Xkl5Ms78rus3PM6wVLuA6qgtyBEFKOu6ChMcmNh2RtybA10hgyPxakDilSZs 73 ZnONPBMGEnBFYGPNZm/VZgsavuIcJNnTDbPFjXyiet3+xEflNDA8PPdEHZXkYRCS 74 Z1bDH+iMm37KbFyJ2i7UTVmP21OFYnoNHcZTuYmbgCm/w9Fvf2vkY5fl3OidFKse 75 MqCB4VwWbEXlCGarrFrhjZ2Vd6M6YCwcq3lX+wC3f7mFwRa39BWZs+VFW2KPhuvr 76 jKR1lWjtM6PIl0mhqhJjShzrb2wgX6RaSVrOs1E+dQL9vNB9hQieShUVyd4m433Y 77 +gpJHeNhVZ+yBuNzm8wB3BB9e4mf4pKB9WFiLO9Gdi35hnldbUne9F78IJXSeIsv 78 MmZIu3hHkHeHcsTXrK9AQuP2XTAxgZ6OjdlmvZ9kGNHxikAKH0reMSOU5IBn6FwX 79 +7uKoU/Gyj5jTruMbwfbkr5SsEg0cG+xIT8l+ml3V7kOm3xYFfPRBhFTJ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