github.com/Night-mk/quorum@v21.1.0+incompatible/extension/data_handler_test.go (about) 1 package extension 2 3 import ( 4 "encoding/json" 5 "io/ioutil" 6 "testing" 7 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestWriteContentsToFileWritesOkay(t *testing.T) { 13 extensionContracts := make(map[common.Address]*ExtensionContract) 14 extensionContracts[common.HexToAddress("0x2222222222222222222222222222222222222222")] = &ExtensionContract{ 15 ContractExtended: common.HexToAddress("0x1111111111111111111111111111111111111111"), 16 Initiator: common.HexToAddress("0x3333333333333333333333333333333333333333"), 17 Recipient: common.HexToAddress("0x4444444444444444444444444444444444444444"), 18 RecipientPtmKey: "1234567891234567891234567891234567891234567=", 19 ManagementContractAddress: common.HexToAddress("0x2222222222222222222222222222222222222222"), 20 CreationData: []byte("Sample Transaction Data"), 21 } 22 23 datadir, err := ioutil.TempDir("", t.Name()) 24 if err != nil { 25 t.Errorf("could not create temp directory for test, error: %s", err.Error()) 26 } 27 28 dataHandler := NewJsonFileDataHandler(datadir) 29 30 if err := dataHandler.Save(extensionContracts); err != nil { 31 t.Errorf("error writing data to file, error: %s", err.Error()) 32 } 33 34 loadedData, err := dataHandler.Load() 35 if err != nil { 36 t.Errorf("error reading data from file, error: %s", err.Error()) 37 } 38 39 if !assert.ObjectsAreEqual(extensionContracts, loadedData) { 40 expected, _ := json.Marshal(extensionContracts) 41 actual, _ := json.Marshal(loadedData) 42 t.Errorf("expected data from file different to data written, expected %v, got %v", string(expected), string(actual)) 43 } 44 }