From f41d335a35c1608c5a5f1dfe54322ba4b3540880 Mon Sep 17 00:00:00 2001 From: Andrew Chiw Date: Tue, 24 Sep 2019 00:55:52 +0200 Subject: [PATCH] chore: config.Config was stuttering --- account/keystore.go | 12 ++-- aeternity/helpers.go | 46 ++++++------ cmd/account.go | 2 +- cmd/chain.go | 2 +- cmd/contract.go | 10 +-- cmd/root.go | 12 ++-- cmd/terminal.go | 2 +- cmd/test_utils.go | 4 +- cmd/tx.go | 14 ++-- cmd/tx_test.go | 2 +- config/config.go | 113 +++++++++++++++++------------- integration_test/aens_test.go | 4 +- integration_test/api_test.go | 14 ++-- integration_test/compiler_test.go | 14 ++-- integration_test/contract_test.go | 4 +- integration_test/ga_test.go | 18 ++--- integration_test/oracle_test.go | 4 +- integration_test/testsetup.go | 6 +- models/transactions.go | 16 ++--- models/tx_contracts_test.go | 24 +++---- models/tx_oracles_test.go | 24 +++---- 21 files changed, 181 insertions(+), 166 deletions(-) diff --git a/account/keystore.go b/account/keystore.go index b8f3238f..b5b2a1c1 100644 --- a/account/keystore.go +++ b/account/keystore.go @@ -104,9 +104,9 @@ func KeystoreSeal(account *Account, password string) (j []byte, e error) { return } argonKey := argon2.IDKey([]byte(password), salt, - config.Config.Tuning.CryptoKdfOpslimit, - config.Config.Tuning.CryptoKdfMemlimit, - config.Config.Tuning.CryptoKdfThreads, + config.Tuning.CryptoKdfOpslimit, + config.Tuning.CryptoKdfMemlimit, + config.Tuning.CryptoKdfThreads, kdfKeySize) var key [kdfKeySize]byte @@ -134,10 +134,10 @@ func KeystoreSeal(account *Account, password string) (j []byte, e error) { Ciphertext: hex.EncodeToString(encrypted), Kdf: kdf, KdfParams: kdfParams{ - Memlimit: config.Config.Tuning.CryptoKdfMemlimit, - Opslimit: config.Config.Tuning.CryptoKdfOpslimit, + Memlimit: config.Tuning.CryptoKdfMemlimit, + Opslimit: config.Tuning.CryptoKdfOpslimit, Salt: hex.EncodeToString(salt), - Parallelism: config.Config.Tuning.CryptoKdfThreads, + Parallelism: config.Tuning.CryptoKdfThreads, }, }, } diff --git a/aeternity/helpers.go b/aeternity/helpers.go index 8a722fb1..4dac0c99 100644 --- a/aeternity/helpers.go +++ b/aeternity/helpers.go @@ -149,7 +149,7 @@ func NewContextFromNode(node *naet.Node, address string) (ctx *Context) { // SpendTx creates a spend transaction, filling in the account nonce and // transaction TTL automatically. func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big.Int, payload []byte) (tx *models.SpendTx, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } @@ -162,7 +162,7 @@ func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big. // nonce and transaction TTL automatically. It also generates a commitment ID // and salt, later used to claim the name. func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *models.NamePreclaimTx, nameSalt *big.Int, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } @@ -183,7 +183,7 @@ func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *models.NamePrec // NameClaimTx creates a claim transaction, filling in the account nonce and // transaction TTL automatically. func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *models.NameClaimTx, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } @@ -197,18 +197,18 @@ func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *models.N // NameUpdateTx creates a name update transaction, filling in the account nonce // and transaction TTL automatically. func (c *Context) NameUpdateTx(name string, targetAddress string) (tx *models.NameUpdateTx, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name)) - absNameTTL, err := c.GetTTL(config.Config.Client.Names.NameTTL) + absNameTTL, err := c.GetTTL(config.Client.Names.NameTTL) if err != nil { return } // create the transaction - tx = models.NewNameUpdateTx(c.Address, encodedNameHash, []string{targetAddress}, absNameTTL, config.Config.Client.Names.ClientTTL, config.Config.Client.Fee, txTTL, accountNonce) + tx = models.NewNameUpdateTx(c.Address, encodedNameHash, []string{targetAddress}, absNameTTL, config.Client.Names.ClientTTL, config.Client.Fee, txTTL, accountNonce) return } @@ -216,95 +216,95 @@ func (c *Context) NameUpdateTx(name string, targetAddress string) (tx *models.Na // NameTransferTx creates a name transfer transaction, filling in the account // nonce and transaction TTL automatically. func (c *Context) NameTransferTx(name string, recipientAddress string) (tx *models.NameTransferTx, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name)) - tx = models.NewNameTransferTx(c.Address, encodedNameHash, recipientAddress, config.Config.Client.Fee, txTTL, accountNonce) + tx = models.NewNameTransferTx(c.Address, encodedNameHash, recipientAddress, config.Client.Fee, txTTL, accountNonce) return } // NameRevokeTx creates a name revoke transaction, filling in the account nonce // and transaction TTL automatically. func (c *Context) NameRevokeTx(name string) (tx *models.NameRevokeTx, err error) { - txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + txTTL, accountNonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } encodedNameHash := binary.Encode(binary.PrefixName, Namehash(name)) - tx = models.NewNameRevokeTx(c.Address, encodedNameHash, config.Config.Client.Fee, txTTL, accountNonce) + tx = models.NewNameRevokeTx(c.Address, encodedNameHash, config.Client.Fee, txTTL, accountNonce) return } // OracleRegisterTx creates an oracle register transaction, filling in the // account nonce and transaction TTL automatically. func (c *Context) OracleRegisterTx(querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, VMVersion uint16) (tx *models.OracleRegisterTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } - tx = models.NewOracleRegisterTx(c.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, VMVersion, config.Config.Client.Fee, ttl) + tx = models.NewOracleRegisterTx(c.Address, nonce, querySpec, responseSpec, queryFee, oracleTTLType, oracleTTLValue, VMVersion, config.Client.Fee, ttl) return tx, nil } // OracleExtendTx creates an oracle extend transaction, filling in the account // nonce and transaction TTL automatically. func (c *Context) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx *models.OracleExtendTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } - tx = models.NewOracleExtendTx(oracleID, nonce, ttlType, ttlValue, config.Config.Client.Fee, ttl) + tx = models.NewOracleExtendTx(oracleID, nonce, ttlType, ttlValue, config.Client.Fee, ttl) return tx, nil } // OracleQueryTx creates an oracle query transaction, filling in the account // nonce and transaction TTL automatically. func (c *Context) OracleQueryTx(OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx *models.OracleQueryTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } - tx = models.NewOracleQueryTx(c.Address, nonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, config.Config.Client.Fee, ttl) + tx = models.NewOracleQueryTx(c.Address, nonce, OracleID, Query, QueryFee, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue, config.Client.Fee, ttl) return tx, nil } // OracleRespondTx creates an oracle response transaction, filling in the // account nonce and transaction TTL automatically. func (c *Context) OracleRespondTx(OracleID string, QueryID string, Response string, TTLType uint64, TTLValue uint64) (tx *models.OracleRespondTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } - tx = models.NewOracleRespondTx(OracleID, nonce, QueryID, Response, TTLType, TTLValue, config.Config.Client.Fee, ttl) + tx = models.NewOracleRespondTx(OracleID, nonce, QueryID, Response, TTLType, TTLValue, config.Client.Fee, ttl) return tx, nil } // ContractCreateTx creates a contract create transaction, filling in the // account nonce and transaction TTL automatically. func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, GasLimit, Fee *big.Int) (tx *models.ContractCreateTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } - tx = models.NewContractCreateTx(c.Address, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, GasLimit, config.Config.Client.GasPrice, Fee, ttl, CallData) + tx = models.NewContractCreateTx(c.Address, nonce, Code, VMVersion, AbiVersion, Deposit, Amount, GasLimit, config.Client.GasPrice, Fee, ttl, CallData) return tx, nil } // ContractCallTx creates a contract call transaction,, filling in the account // nonce and transaction TTL automatically. func (c *Context) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, GasLimit, GasPrice, Fee *big.Int) (tx *models.ContractCallTx, err error) { - ttl, nonce, err := c.GetTTLNonce(c.Address, config.Config.Client.TTL) + ttl, nonce, err := c.GetTTLNonce(c.Address, config.Client.TTL) if err != nil { return } @@ -346,7 +346,7 @@ type getTransactionByHashHeighter interface { // WaitForTransactionForXBlocks blocks until a transaction has been mined or X // blocks have gone by, after which it returns an error. The node polling -// interval can be config.Configured with config.Config.Tuning.ChainPollInterval. +// interval can be config.Configured with config.Tuning.ChainPollInterval. func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, x uint64) (blockHeight uint64, blockHash string, err error) { nodeHeight, err := c.GetHeight() if err != nil { @@ -367,7 +367,7 @@ func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, bh := big.Int(tx.BlockHeight) return bh.Uint64(), *tx.BlockHash, nil } - time.Sleep(time.Millisecond * time.Duration(config.Config.Tuning.ChainPollInterval)) + time.Sleep(time.Millisecond * time.Duration(config.Tuning.ChainPollInterval)) } return 0, "", fmt.Errorf("%v blocks have gone by and %v still isn't in a block", x, txHash) } diff --git a/cmd/account.go b/cmd/account.go index 471a9922..7bb9ee3c 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -174,7 +174,7 @@ func signFunc(cmd *cobra.Command, args []string) (err error) { return err } - txSignedBase64, txHash, signature, err := models.SignHashTx(account, tx, config.Config.Node.NetworkID) + txSignedBase64, txHash, signature, err := models.SignHashTx(account, tx, config.Node.NetworkID) if err != nil { return err } diff --git a/cmd/chain.go b/cmd/chain.go index e036cd43..d5569f99 100644 --- a/cmd/chain.go +++ b/cmd/chain.go @@ -174,7 +174,7 @@ func ttlFunc(conn naet.GetHeighter, args []string) (err error) { errFinal := fmt.Errorf("Error getting height from the node: %v", err) return errFinal } - ttl = height + config.Config.Client.TTL + ttl = height + config.Client.TTL fmt.Println(ttl) return nil } diff --git a/cmd/contract.go b/cmd/contract.go index d15f1872..902f89a7 100644 --- a/cmd/contract.go +++ b/cmd/contract.go @@ -35,7 +35,7 @@ func compileFunc(conn naet.CompileContracter, args []string) (err error) { return err } - bytecode, err := conn.CompileContract(s, config.Config.Compiler.Backend) + bytecode, err := conn.CompileContract(s, config.Compiler.Backend) fmt.Println(bytecode) return err } @@ -58,7 +58,7 @@ func encodeCalldataFunc(conn naet.EncodeCalldataer, args []string) (err error) { return err } - callData, err := conn.EncodeCalldata(s, args[1], args[2:], config.Config.Compiler.Backend) + callData, err := conn.EncodeCalldata(s, args[1], args[2:], config.Compiler.Backend) if err != nil { return err } @@ -91,7 +91,7 @@ func decodeCalldataBytecodeFunc(conn decodeCalldataer, args []string) (err error return fmt.Errorf("%s is not bytecode", args[0]) } - r, err := conn.DecodeCalldataBytecode(args[0], args[1], config.Config.Compiler.Backend) + r, err := conn.DecodeCalldataBytecode(args[0], args[1], config.Compiler.Backend) if err != nil { return } @@ -121,7 +121,7 @@ func decodeCalldataSourceFunc(conn decodeCalldataer, args []string) (err error) return fmt.Errorf("%s is not bytecode", args[0]) } - r, err := conn.DecodeCalldataSource(source, args[1], args[2], config.Config.Compiler.Backend) + r, err := conn.DecodeCalldataSource(source, args[1], args[2], config.Compiler.Backend) fmt.Println(*r.Function, r.Arguments) return @@ -145,7 +145,7 @@ func generateAciFunc(conn naet.GenerateACIer, args []string) (err error) { return } - aci, err := conn.GenerateACI(source, config.Config.Compiler.Backend) + aci, err := conn.GenerateACI(source, config.Compiler.Backend) if err != nil { return } diff --git a/cmd/root.go b/cmd/root.go index 09aef2b2..c51a8cf9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -52,7 +52,7 @@ func Execute(v string) { // read immediately, with this helper function you can defer the reading of the // variables until the subcommand's execution) func newAeNode() naet.NodeInterface { - return naet.NewNode(config.Config.Node.URL, debug) + return naet.NewNode(config.Node.URL, debug) } // newCompiler is just a helper function that gives you a Compiler so that you don't @@ -67,15 +67,15 @@ func init() { // cobra.OnInitialize(initConfig) viper.AutomaticEnv() // read in environment variables that match viper.SetEnvPrefix("AETERNITY") - viper.SetDefault("external-api", config.Config.Node.URL) - viper.SetDefault("network-id", config.Config.Node.NetworkID) + viper.SetDefault("external-api", config.Node.URL) + viper.SetDefault("network-id", config.Node.NetworkID) // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags, which, if defined here, // will be global for your application. - RootCmd.PersistentFlags().StringVarP(&config.Config.Node.URL, "external-api", "u", config.Config.Node.URL, "node external API endpoint") - RootCmd.PersistentFlags().StringVarP(&config.Config.Node.NetworkID, "network-id", "n", config.Config.Node.NetworkID, "network ID for custom private net") + RootCmd.PersistentFlags().StringVarP(&config.Node.URL, "external-api", "u", config.Node.URL, "node external API endpoint") + RootCmd.PersistentFlags().StringVarP(&config.Node.NetworkID, "network-id", "n", config.Node.NetworkID, "network ID for custom private net") RootCmd.PersistentFlags().StringVarP(&compilerURL, "compiler-url", "c", "http://localhost:3080", "Compiler URL") RootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug") - RootCmd.PersistentFlags().BoolVar(&config.Config.Tuning.OutputFormatJSON, "json", false, "print output in json format") + RootCmd.PersistentFlags().BoolVar(&config.Tuning.OutputFormatJSON, "json", false, "print output in json format") } diff --git a/cmd/terminal.go b/cmd/terminal.go index 4d7893c4..2b549332 100644 --- a/cmd/terminal.go +++ b/cmd/terminal.go @@ -101,7 +101,7 @@ func printIf(title string, v interface{}) { // PrintObject pretty print an object obtained from the api with a title func PrintObject(title string, i interface{}) { - if config.Config.Tuning.OutputFormatJSON { + if config.Tuning.OutputFormatJSON { j, _ := json.MarshalIndent(i, "", " ") fmt.Printf("%s\n", j) return diff --git a/cmd/test_utils.go b/cmd/test_utils.go index 8319c320..ce8e3400 100644 --- a/cmd/test_utils.go +++ b/cmd/test_utils.go @@ -12,8 +12,8 @@ import ( ) func setPrivateNetParams() { - config.Config.Node.URL = "http://localhost:3013" - config.Config.Node.NetworkID = "ae_docker" + config.Node.URL = "http://localhost:3013" + config.Node.NetworkID = "ae_docker" } // dumpV serializes and prints out any swagger model in JSON. Useful when diff --git a/cmd/tx.go b/cmd/tx.go index f81fbe2b..53f1aff5 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -79,7 +79,7 @@ func txSpendFunc(ttlFunc aeternity.GetTTLFunc, nonceFunc aeternity.GetNextNonceF // If TTL was not specified as an argument, connect to the node to calculate // it if ttl == 0 { - ttl, err = ttlFunc(config.Config.Client.TTL) + ttl, err = ttlFunc(config.Client.TTL) if err != nil { return err } @@ -156,13 +156,13 @@ func txContractCreateFunc(ttlFunc aeternity.GetTTLFunc, nonceFunc aeternity.GetN // If TTL was not specified as an argument, connect to the node to calculate // it if ttl == 0 { - ttl, err = ttlFunc(config.Config.Client.TTL) + ttl, err = ttlFunc(config.Client.TTL) if err != nil { return err } } - tx := models.NewContractCreateTx(owner, nonce, contract, config.Config.Client.Contracts.VMVersion, config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Deposit, config.Config.Client.Contracts.Amount, config.Config.Client.Contracts.GasLimit, config.Config.Client.GasPrice, config.Config.Client.Fee, ttl, calldata) + tx := models.NewContractCreateTx(owner, nonce, contract, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, config.Client.Contracts.GasLimit, config.Client.GasPrice, config.Client.Fee, ttl, calldata) txStr, err := models.SerializeTx(tx) if err != nil { @@ -211,15 +211,15 @@ func txVerifyFunc(cmd *cobra.Command, args []string) (err error) { if !IsTransaction(txSignedBase64) { return errors.New("Error, missing or invalid base64 encoded transaction") } - valid, err := aeternity.VerifySignedTx(sender, txSignedBase64, config.Config.Node.NetworkID) + valid, err := aeternity.VerifySignedTx(sender, txSignedBase64, config.Node.NetworkID) if err != nil { err := fmt.Errorf("error while verifying signature: %s", err) return err } if valid { - fmt.Printf("The signature is valid (network-id: %s)\n", config.Config.Node.NetworkID) + fmt.Printf("The signature is valid (network-id: %s)\n", config.Node.NetworkID) } else { - message := fmt.Sprintf("The signature is invalid (expecting network-id: %s)", config.Config.Node.NetworkID) + message := fmt.Sprintf("The signature is invalid (expecting network-id: %s)", config.Node.NetworkID) // fmt.Println(message) err = errors.New(message) } @@ -258,7 +258,7 @@ func init() { txCmd.AddCommand(txDumpRawCmd) // tx spend command - txSpendCmd.Flags().StringVar(&fee, "fee", config.Config.Client.Fee.String(), fmt.Sprintf("Set the transaction fee (default=%s)", config.Config.Client.Fee.String())) + txSpendCmd.Flags().StringVar(&fee, "fee", config.Client.Fee.String(), fmt.Sprintf("Set the transaction fee (default=%s)", config.Client.Fee.String())) txSpendCmd.Flags().Uint64Var(&ttl, "ttl", 0, fmt.Sprintf("Set the TTL in keyblocks (default=%d)", 0)) txSpendCmd.Flags().Uint64Var(&nonce, "nonce", 0, fmt.Sprint("Set the sender account nonce, if not the chain will be queried for its value")) txSpendCmd.Flags().StringVar(&spendTxPayload, "payload", "", fmt.Sprint("Optional text payload for Spend Transactions, which will be turned into a bytearray")) diff --git a/cmd/tx_test.go b/cmd/tx_test.go index 976267df..a77e2815 100644 --- a/cmd/tx_test.go +++ b/cmd/tx_test.go @@ -45,7 +45,7 @@ func TestTxVerify(t *testing.T) { // unsigned tx_+FMMAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjCoa15iD0gACCAfQBgIHqJ/Y= // sign with ae_mainnet signedTx := "tx_+J0LAfhCuEBcvwtyCo3FYqmINcP6lHLH/dRDcj5rUiKDqYKhPpiQ+1SBQ66rF3gdVQ1IcANcw/IayK//YgK2dsDF1VtroQEAuFX4UwwBoQHOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+86EBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMKhrXmIPSAAIIB9AGAx+EjLg==" - config.Config.Node.NetworkID = "ae_mainnet" + config.Node.NetworkID = "ae_mainnet" emptyCmd := cobra.Command{} err := txVerifyFunc(&emptyCmd, []string{alice, signedTx}) diff --git a/config/config.go b/config/config.go index f7d71d8b..ba279a6c 100644 --- a/config/config.go +++ b/config/config.go @@ -4,7 +4,9 @@ import ( "math/big" ) -// Acceptable values for various parameters +// The main purpose of these constants is to relieve the user from having to +// remember the exact underlying value for a particular setting. They are also +// unlikely to change. const ( // NetworkIDMainnet is the network ID for aeternity mainnet NetworkIDMainnet = "ae_mainnet" @@ -138,56 +140,69 @@ type ProfileConfig struct { Tuning TuningConfig `json:"tuning" yaml:"tuning" mapstructure:"tuning"` } -// Config specifies defaults for all configuration parameters -var Config = ProfileConfig{ - Name: "Default Config", - Node: NodeConfig{ - URL: "https://sdk-mainnet.aepps.com", - URLInternal: "https://sdk-mainnet.aepps.com", - URLChannels: "https://sdk-mainnet.aepps.com", - NetworkID: "ae_mainnet", +// Node holds default settings for NodeConfig +var Node = NodeConfig{ + URL: "https://sdk-mainnet.aepps.com", + URLInternal: "https://sdk-mainnet.aepps.com", + URLChannels: "https://sdk-mainnet.aepps.com", + NetworkID: "ae_mainnet", +} + +// Compiler holds default settings for CompilerConfig +var Compiler = CompilerConfig{ + URL: "http://localhost:3080", + Backend: CompilerBackendAEVM, +} + +// Client holds default settings for ClientConfig +var Client = ClientConfig{ + BaseGas: big.NewInt(15000), + GasPerByte: big.NewInt(20), + GasPrice: big.NewInt(1e9), + TTL: 500, + Fee: big.NewInt(2e14), + Names: AensConfig{ + NameTTL: 500, + ClientTTL: 500, }, - Compiler: CompilerConfig{ - URL: "http://localhost:3080", - Backend: CompilerBackendAEVM, + Contracts: ContractConfig{ + CompilerURL: "http://localhost:3080", + GasLimit: big.NewInt(1e9), + Amount: new(big.Int), + Deposit: new(big.Int), + VMVersion: 4, + ABIVersion: 1, }, - Client: ClientConfig{ - BaseGas: big.NewInt(15000), - GasPerByte: big.NewInt(20), - GasPrice: big.NewInt(1e9), - TTL: 500, - Fee: big.NewInt(2e14), - Names: AensConfig{ - NameTTL: 500, - ClientTTL: 500, - }, - Contracts: ContractConfig{ - CompilerURL: "http://localhost:3080", - GasLimit: big.NewInt(1e9), - Amount: new(big.Int), - Deposit: new(big.Int), - VMVersion: 4, - ABIVersion: 1, - }, - Oracles: OracleConfig{ - QueryFee: big.NewInt(0), - QueryTTLType: OracleTTLTypeDelta, - QueryTTLValue: 300, - ResponseTTLType: OracleTTLTypeDelta, - ResponseTTLValue: 300, - VMVersion: 0, - }, - StateChannels: StateChannelConfig{ // UNUSED - LockPeriod: 0, - ChannelReserve: 0, - }, + Oracles: OracleConfig{ + QueryFee: big.NewInt(0), + QueryTTLType: OracleTTLTypeDelta, + QueryTTLValue: 300, + ResponseTTLType: OracleTTLTypeDelta, + ResponseTTLValue: 300, + VMVersion: 0, }, - Tuning: TuningConfig{ - ChainPollInterval: 100, - ChainTimeout: 5000, - CryptoKdfMemlimit: 1024 * 32, // 32MB - CryptoKdfOpslimit: 3, - CryptoKdfThreads: 1, - OutputFormatJSON: false, + StateChannels: StateChannelConfig{ // UNUSED + LockPeriod: 0, + ChannelReserve: 0, }, } + +// Tuning holds default settings for TuningConfig +var Tuning = TuningConfig{ + ChainPollInterval: 100, + ChainTimeout: 5000, + CryptoKdfMemlimit: 1024 * 32, // 32MB + CryptoKdfOpslimit: 3, + CryptoKdfThreads: 1, + OutputFormatJSON: false, +} + +// Profile collects the default settings together to form a settings profile +// that can be saved/loaded. +var Profile = ProfileConfig{ + Name: "Default Config", + Node: Node, + Compiler: Compiler, + Client: Client, + Tuning: Tuning, +} diff --git a/integration_test/aens_test.go b/integration_test/aens_test.go index ad87b034..294c34f4 100644 --- a/integration_test/aens_test.go +++ b/integration_test/aens_test.go @@ -42,7 +42,7 @@ func TestAENSWorkflow(t *testing.T) { name := randomName(6) // Preclaim the name - preclaimTx, salt, err := aensAlice.NamePreclaimTx(name, config.Config.Client.Fee) + preclaimTx, salt, err := aensAlice.NamePreclaimTx(name, config.Client.Fee) if err != nil { t.Fatal(err) } @@ -56,7 +56,7 @@ func TestAENSWorkflow(t *testing.T) { _, _, _ = waitForTransaction(node, hash) // Claim the name - claimTx, err := aensAlice.NameClaimTx(name, salt, config.Config.Client.Fee) + claimTx, err := aensAlice.NameClaimTx(name, salt, config.Client.Fee) if err != nil { t.Fatal(err) } diff --git a/integration_test/api_test.go b/integration_test/api_test.go index 02051ff4..502c4425 100644 --- a/integration_test/api_test.go +++ b/integration_test/api_test.go @@ -121,7 +121,7 @@ func TestAPI(t *testing.T) { ctxBob := aeternity.NewContextFromNode(privateNet, bob.Address) // SpendTx fmt.Println("SpendTx") - spendTx, err := ctxAlice.SpendTx(sender, bob.Address, big.NewInt(1000), config.Config.Client.Fee, []byte("")) + spendTx, err := ctxAlice.SpendTx(sender, bob.Address, big.NewInt(1000), config.Client.Fee, []byte("")) if err != nil { t.Fatal(err) } @@ -129,7 +129,7 @@ func TestAPI(t *testing.T) { // NamePreClaimTx fmt.Println("NamePreClaimTx") - preclaimTx, salt, err := ctxAlice.NamePreclaimTx(name, config.Config.Client.Fee) + preclaimTx, salt, err := ctxAlice.NamePreclaimTx(name, config.Client.Fee) if err != nil { t.Fatal(err) } @@ -137,7 +137,7 @@ func TestAPI(t *testing.T) { // NameClaimTx fmt.Println("NameClaimTx") - claimTx, err := ctxAlice.NameClaimTx(name, salt, config.Config.Client.Fee) + claimTx, err := ctxAlice.NameClaimTx(name, salt, config.Client.Fee) if err != nil { t.Fatal(err) } @@ -170,7 +170,7 @@ func TestAPI(t *testing.T) { sentTxs.name = randomName(8) // NamePreClaimTx fmt.Println("NamePreClaimTx 2nd name for other tests") - preclaimTx, salt, err = ctxAlice.NamePreclaimTx(sentTxs.name, config.Config.Client.Fee) + preclaimTx, salt, err = ctxAlice.NamePreclaimTx(sentTxs.name, config.Client.Fee) if err != nil { t.Fatal(err) } @@ -178,7 +178,7 @@ func TestAPI(t *testing.T) { // NameClaimTx fmt.Println("NameClaimTx 2nd name for other tests") - claimTx, err = ctxAlice.NameClaimTx(sentTxs.name, salt, config.Config.Client.Fee) + claimTx, err = ctxAlice.NameClaimTx(sentTxs.name, salt, config.Client.Fee) if err != nil { t.Fatal(err) } @@ -227,7 +227,7 @@ func TestAPI(t *testing.T) { fmt.Println("ContractCreateTx") ctCreateBytecode := golden.Get(t, "identity_bytecode.txt") ctCreateInitCalldata := golden.Get(t, "identity_initcalldata.txt") - ctCreate, err := ctxAlice.ContractCreateTx(string(ctCreateBytecode), string(ctCreateInitCalldata), config.Config.Client.Contracts.VMVersion, config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Deposit, config.Config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000)) + ctCreate, err := ctxAlice.ContractCreateTx(string(ctCreateBytecode), string(ctCreateInitCalldata), config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000)) if err != nil { t.Fatal(err) } @@ -241,7 +241,7 @@ func TestAPI(t *testing.T) { // ContractCallTx fmt.Println("ContractCallTx") ctCallCalldata := golden.Get(t, "identity_main42.txt") - ctCall, err := ctxAlice.ContractCallTx(sentTxs.contractID, string(ctCallCalldata), config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Config.Client.GasPrice, utils.NewIntFromUint64(665480000000000)) + ctCall, err := ctxAlice.ContractCallTx(sentTxs.contractID, string(ctCallCalldata), config.Client.Contracts.ABIVersion, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Client.GasPrice, utils.NewIntFromUint64(665480000000000)) if err != nil { t.Fatal(err) } diff --git a/integration_test/compiler_test.go b/integration_test/compiler_test.go index dd545d7b..c1f252b7 100644 --- a/integration_test/compiler_test.go +++ b/integration_test/compiler_test.go @@ -23,7 +23,7 @@ func TestCompiler(t *testing.T) { } }) t.Run("CompileContract", func(t *testing.T) { - compiled, err := c.CompileContract(string(golden.Get(t, simplestorageSource)), config.Config.Compiler.Backend) + compiled, err := c.CompileContract(string(golden.Get(t, simplestorageSource)), config.Compiler.Backend) if err != nil { t.Error(err) } @@ -48,19 +48,19 @@ func TestCompiler(t *testing.T) { }) t.Run("DecodeCallResult", func(t *testing.T) { // taken from contract_test.go - _, err := c.DecodeCallResult("ok", "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACr8s/aY", "main", string(golden.Get(t, identitySource)), config.Config.Compiler.Backend) + _, err := c.DecodeCallResult("ok", "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACr8s/aY", "main", string(golden.Get(t, identitySource)), config.Compiler.Backend) if err != nil { t.Error(err) } }) t.Run("DecodeCalldataBytecode", func(t *testing.T) { - _, err := c.DecodeCalldataBytecode(string(golden.Get(t, simplestorageBytecode)), string(golden.Get(t, simplestorageCalldata)), config.Config.Compiler.Backend) + _, err := c.DecodeCalldataBytecode(string(golden.Get(t, simplestorageBytecode)), string(golden.Get(t, simplestorageCalldata)), config.Compiler.Backend) if err != nil { t.Error(err) } }) t.Run("DecodeCalldataSource", func(t *testing.T) { - _, err := c.DecodeCalldataSource(string(golden.Get(t, simplestorageSource)), "init", string(golden.Get(t, simplestorageCalldata)), config.Config.Compiler.Backend) + _, err := c.DecodeCalldataSource(string(golden.Get(t, simplestorageSource)), "init", string(golden.Get(t, simplestorageCalldata)), config.Compiler.Backend) if err != nil { t.Error(err) } @@ -73,21 +73,21 @@ func TestCompiler(t *testing.T) { } }) t.Run("EncodeCalldata SimpleStorage set(123)", func(t *testing.T) { - encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "set", []string{"123"}, config.Config.Compiler.Backend) + encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "set", []string{"123"}, config.Compiler.Backend) if err != nil { t.Error(err) } golden.Assert(t, encodedCalldata, "simplestorage_set123.txt") }) t.Run("EncodeCalldata SimpleStorage init(42)", func(t *testing.T) { - encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "init", []string{"42"}, config.Config.Compiler.Backend) + encodedCalldata, err := c.EncodeCalldata(string(golden.Get(t, simplestorageSource)), "init", []string{"42"}, config.Compiler.Backend) if err != nil { t.Error(err) } golden.Assert(t, encodedCalldata, "simplestorage_init42.txt") }) t.Run("GenerateACI", func(t *testing.T) { - _, err := c.GenerateACI(string(golden.Get(t, simplestorageSource)), config.Config.Compiler.Backend) + _, err := c.GenerateACI(string(golden.Get(t, simplestorageSource)), config.Compiler.Backend) if err != nil { t.Error(err) } diff --git a/integration_test/contract_test.go b/integration_test/contract_test.go index 91d0256a..626c74a7 100644 --- a/integration_test/contract_test.go +++ b/integration_test/contract_test.go @@ -20,7 +20,7 @@ func TestContracts(t *testing.T) { identityBytecode := string(golden.Get(t, "identity_bytecode.txt")) identityInitCalldata := string(golden.Get(t, "identity_initcalldata.txt")) - create, err := contractsAlice.ContractCreateTx(identityBytecode, identityInitCalldata, config.Config.Client.Contracts.VMVersion, config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Deposit, config.Config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000)) + create, err := contractsAlice.ContractCreateTx(identityBytecode, identityInitCalldata, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.Contracts.Deposit, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), utils.NewIntFromUint64(564480000000000)) if err != nil { t.Fatal(err) } @@ -45,7 +45,7 @@ func TestContracts(t *testing.T) { delay(getContract) identityMain42Calldata := string(golden.Get(t, "identity_main42.txt")) - callTx, err := contractsAlice.ContractCallTx(ctID, identityMain42Calldata, config.Config.Client.Contracts.ABIVersion, config.Config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Config.Client.GasPrice, utils.NewIntFromUint64(665480000000000)) + callTx, err := contractsAlice.ContractCallTx(ctID, identityMain42Calldata, config.Client.Contracts.ABIVersion, config.Client.Contracts.Amount, utils.NewIntFromUint64(1e5), config.Client.GasPrice, utils.NewIntFromUint64(665480000000000)) if err != nil { t.Fatal(err) } diff --git a/integration_test/ga_test.go b/integration_test/ga_test.go index 4b9abd43..be64acba 100644 --- a/integration_test/ga_test.go +++ b/integration_test/ga_test.go @@ -27,7 +27,7 @@ func EncodeRLPToBytes(tx rlp.Encoder) (b []byte, err error) { func TestGeneralizedAccounts(t *testing.T) { alice, bob := setupAccounts(t) node := setupNetwork(t, privatenetURL, false) - compiler := naet.NewCompiler(config.Config.Client.Contracts.CompilerURL, false) + compiler := naet.NewCompiler(config.Client.Contracts.CompilerURL, false) ttlFunc := aeternity.GenerateGetTTL(node) // Take note of Bob's balance, and after this test, we expect it to have this much more AE @@ -43,11 +43,11 @@ func TestGeneralizedAccounts(t *testing.T) { authorizeSource := string(golden.Get(t, "authorize.aes")) // Read the auth contract from a file, compile and prepare its init() calldata - authBytecode, err := compiler.CompileContract(authorizeSource, config.Config.Compiler.Backend) + authBytecode, err := compiler.CompileContract(authorizeSource, config.Compiler.Backend) if err != nil { t.Fatal(err) } - authInitCalldata, err := compiler.EncodeCalldata(authorizeSource, "init", []string{alice.Address}, config.Config.Compiler.Backend) + authInitCalldata, err := compiler.EncodeCalldata(authorizeSource, "init", []string{alice.Address}, config.Compiler.Backend) if err != nil { t.Fatal(err) } @@ -72,11 +72,11 @@ func TestGeneralizedAccounts(t *testing.T) { if err != nil { t.Fatal(err) } - ttl, err := ttlFunc(config.Config.Client.TTL) + ttl, err := ttlFunc(config.Client.TTL) if err != nil { t.Fatal(err) } - gaTx := models.NewGAAttachTx(testAccount.Address, 1, authBytecode, auth.TypeInfo[0].FuncHash, config.Config.Client.Contracts.VMVersion, config.Config.Client.Contracts.ABIVersion, config.Config.Client.BaseGas, config.Config.Client.GasPrice, config.Config.Client.Fee, ttl, authInitCalldata) + gaTx := models.NewGAAttachTx(testAccount.Address, 1, authBytecode, auth.TypeInfo[0].FuncHash, config.Client.Contracts.VMVersion, config.Client.Contracts.ABIVersion, config.Client.BaseGas, config.Client.GasPrice, config.Client.Fee, ttl, authInitCalldata) _, txHash, _, err := aeternity.SignBroadcastTransaction(gaTx, testAccount, node, networkID) if err != nil { t.Fatal(err) @@ -100,7 +100,7 @@ func TestGeneralizedAccounts(t *testing.T) { // GAMetaTx // Get the TTL (not really needed, could be 0 too) - ttl, err = ttlFunc(config.Config.Client.TTL) + ttl, err = ttlFunc(config.Client.TTL) if err != nil { t.Fatal(err) } @@ -110,10 +110,10 @@ func TestGeneralizedAccounts(t *testing.T) { // authData is authorize(3) authData := "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBGtXufEG2HuMYcRcNwsGAeqymslunKf692bHnvwI5K6wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU3aKBNm" gas := utils.NewIntFromUint64(10000) // the node will fail the authentication if there isn't enough gas - spendTx := models.NewSpendTx(testAccount.Address, bob.Address, big.NewInt(5000), config.Config.Client.Fee, []byte{}, ttl, 0) - gaMetaTx := models.NewGAMetaTx(testAccount.Address, authData, config.Config.Client.Contracts.ABIVersion, gas, config.Config.Client.GasPrice, config.Config.Client.Fee, ttl, spendTx) + spendTx := models.NewSpendTx(testAccount.Address, bob.Address, big.NewInt(5000), config.Client.Fee, []byte{}, ttl, 0) + gaMetaTx := models.NewGAMetaTx(testAccount.Address, authData, config.Client.Contracts.ABIVersion, gas, config.Client.GasPrice, config.Client.Fee, ttl, spendTx) - gaMetaTxFinal, hash, _, err := models.SignHashTx(testAccount, gaMetaTx, config.Config.Node.NetworkID) + gaMetaTxFinal, hash, _, err := models.SignHashTx(testAccount, gaMetaTx, config.Node.NetworkID) if err != nil { t.Fatal(err) } diff --git a/integration_test/oracle_test.go b/integration_test/oracle_test.go index a1cdc01a..488e2b0e 100644 --- a/integration_test/oracle_test.go +++ b/integration_test/oracle_test.go @@ -25,7 +25,7 @@ func TestOracleWorkflow(t *testing.T) { oracleAccount := aeternity.NewContextFromNode(node, testAccount.Address) // Register - register, err := oracleAccount.OracleRegisterTx("hello", "helloback", config.Config.Client.Oracles.QueryFee, config.Config.Client.Oracles.QueryTTLType, config.Config.Client.Oracles.QueryTTLValue, config.Config.Client.Oracles.VMVersion) + register, err := oracleAccount.OracleRegisterTx("hello", "helloback", config.Client.Oracles.QueryFee, config.Client.Oracles.QueryTTLType, config.Client.Oracles.QueryTTLValue, config.Client.Oracles.VMVersion) if err != nil { t.Fatal(err) } @@ -71,7 +71,7 @@ func TestOracleWorkflow(t *testing.T) { } // Query - query, err := oracleAccount.OracleQueryTx(oraclePubKey, "How was your day?", config.Config.Client.Oracles.QueryFee, 0, 100, 0, 100) + query, err := oracleAccount.OracleQueryTx(oraclePubKey, "How was your day?", config.Client.Oracles.QueryFee, 0, 100, 0, 100) if err != nil { t.Fatal(err) } diff --git a/integration_test/testsetup.go b/integration_test/testsetup.go index d141af0a..6ea00f4e 100644 --- a/integration_test/testsetup.go +++ b/integration_test/testsetup.go @@ -22,9 +22,9 @@ var testnetURL = "http://sdk-testnet.aepps.com" var networkID = "ae_docker" func setupNetwork(t *testing.T, nodeURL string, debug bool) *naet.Node { - config.Config.Node.NetworkID = networkID + config.Node.NetworkID = networkID client := naet.NewNode(nodeURL, debug) - t.Logf("nodeURL: %s, networkID: %s", nodeURL, config.Config.Node.NetworkID) + t.Logf("nodeURL: %s, networkID: %s", nodeURL, config.Node.NetworkID) return client } @@ -81,7 +81,7 @@ func fundAccount(t *testing.T, node *naet.Node, source, destination *account.Acc ctx := aeternity.NewContextFromNode(node, source.Address) fmt.Println("Funding account", destination.Address) - tx, err := ctx.SpendTx(source.Address, destination.Address, amount, config.Config.Client.Fee, []byte{}) + tx, err := ctx.SpendTx(source.Address, destination.Address, amount, config.Client.Fee, []byte{}) if err != nil { t.Fatal(err) } diff --git a/models/transactions.go b/models/transactions.go index 4ee278b8..d23d033d 100644 --- a/models/transactions.go +++ b/models/transactions.go @@ -247,32 +247,32 @@ func buildPointers(pointers []string) (ptrs []*NamePointer, err error) { } func calcFeeStd(tx rlp.Encoder, txLen int) *big.Int { - // (config.Config.Client.BaseGas + len(txRLP) * config.Config.Client.GasPerByte) * config.Config.Client.GasPrice + // (config.Client.BaseGas + len(txRLP) * config.Client.GasPerByte) * config.Client.GasPrice // txLenGasPerByte fee := new(big.Int) txLenGasPerByte := new(big.Int) - txLenGasPerByte.Mul(utils.NewIntFromUint64(uint64(txLen)), config.Config.Client.GasPerByte) - fee.Add(config.Config.Client.BaseGas, txLenGasPerByte) - fee.Mul(fee, config.Config.Client.GasPrice) + txLenGasPerByte.Mul(utils.NewIntFromUint64(uint64(txLen)), config.Client.GasPerByte) + fee.Add(config.Client.BaseGas, txLenGasPerByte) + fee.Mul(fee, config.Client.GasPrice) return fee } func calcFeeContract(gas *big.Int, baseGasMultiplier int64, length int) *big.Int { - // (config.Config.Client.BaseGas * 5) + gaslimit + (len(txRLP) * config.Config.Client.GasPerByte) * config.Config.Client.GasPrice + // (config.Client.BaseGas * 5) + gaslimit + (len(txRLP) * config.Client.GasPerByte) * config.Client.GasPrice // baseGas5 txLenGasPerByte baseGas5 := new(big.Int) txLenBig := new(big.Int) answer := new(big.Int) - baseGas5.Mul(config.Config.Client.BaseGas, big.NewInt(baseGasMultiplier)) + baseGas5.Mul(config.Client.BaseGas, big.NewInt(baseGasMultiplier)) txLenBig.SetUint64(uint64(length)) txLenGasPerByte := new(big.Int) - txLenGasPerByte.Mul(txLenBig, config.Config.Client.GasPerByte) + txLenGasPerByte.Mul(txLenBig, config.Client.GasPerByte) answer.Add(baseGas5, gas) answer.Add(answer, txLenGasPerByte) - answer.Mul(answer, config.Config.Client.GasPrice) + answer.Mul(answer, config.Client.GasPrice) return answer } diff --git a/models/tx_contracts_test.go b/models/tx_contracts_test.go index 9dc3d7f8..58c82f2f 100644 --- a/models/tx_contracts_test.go +++ b/models/tx_contracts_test.go @@ -69,12 +69,12 @@ func TestContractTx(t *testing.T) { Code: `cb_+QP1RgKgpVq1Ib2r2ug+UktHvfWSQ8P35HJQHM6qikqBu1DwgtT5Avv5ASqgaPJnYzj/UIg5q6R3Se/6i+h+8oTyB/s9mZhwHNU4h8WEbWFpbrjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKD//////////////////////////////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+QHLoLnJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqhGluaXS4YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////////////////////////////////////7kBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////////////////////////////////////////uMxiAABkYgAAhJGAgIBRf7nJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqFGIAAMBXUIBRf2jyZ2M4/1CIOaukd0nv+ovofvKE8gf7PZmYcBzVOIfFFGIAAK9XUGABGVEAW2AAGVlgIAGQgVJgIJADYAOBUpBZYABRWVJgAFJgAPNbYACAUmAA81tZWWAgAZCBUmAgkANgABlZYCABkIFSYCCQA2ADgVKBUpBWW2AgAVFRWVCAkVBQgJBQkFZbUFCCkVBQYgAAjFaFMi4xLjBJtQib`, VMVersion: 4, AbiVersion: 1, - Deposit: config.Config.Client.Contracts.Deposit, - Amount: config.Config.Client.Contracts.Amount, - GasLimit: config.Config.Client.Contracts.GasLimit, - GasPrice: config.Config.Client.GasPrice, - Fee: config.Config.Client.Fee, - TTL: config.Config.Client.TTL, + Deposit: config.Client.Contracts.Deposit, + Amount: config.Client.Contracts.Amount, + GasLimit: config.Client.Contracts.GasLimit, + GasPrice: config.Client.GasPrice, + Fee: config.Client.Fee, + TTL: config.Client.TTL, CallData: "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC5yVbyizFJqfWYeqUF89obIgnMVzkjQAYrtsG9n5+Z6gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnHQYrA==", }, wantJSON: `{"abi_version":1,"amount":0,"call_data":"cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC5yVbyizFJqfWYeqUF89obIgnMVzkjQAYrtsG9n5+Z6gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnHQYrA==","code":"cb_+QP1RgKgpVq1Ib2r2ug+UktHvfWSQ8P35HJQHM6qikqBu1DwgtT5Avv5ASqgaPJnYzj/UIg5q6R3Se/6i+h+8oTyB/s9mZhwHNU4h8WEbWFpbrjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKD//////////////////////////////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+QHLoLnJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqhGluaXS4YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////////////////////////////////////7kBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA//////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////////////////////////////////////////uMxiAABkYgAAhJGAgIBRf7nJVvKLMUmp9Zh6pQXz2hsiCcxXOSNABiu2wb2fn5nqFGIAAMBXUIBRf2jyZ2M4/1CIOaukd0nv+ovofvKE8gf7PZmYcBzVOIfFFGIAAK9XUGABGVEAW2AAGVlgIAGQgVJgIJADYAOBUpBZYABRWVJgAFJgAPNbYACAUmAA81tZWWAgAZCBUmAgkANgABlZYCABkIFSYCCQA2ADgVKBUpBWW2AgAVFRWVCAkVBQgJBQkFZbUFCCkVBQYgAAjFaFMi4xLjBJtQib","deposit":0,"fee":200000000000000,"gas":1000000000,"gas_price":1000000000,"nonce":1,"owner_id":"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","ttl":500,"vm_version":4}`, @@ -123,13 +123,13 @@ func TestContractTx(t *testing.T) { CallerID: "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi", AccountNonce: uint64(2), ContractID: "ct_2pfWWzeRzWSdm68HXZJn61KhxdsBA46wzYgvo1swkdJZij1rKm", - Amount: config.Config.Client.Contracts.Amount, - GasLimit: config.Config.Client.Contracts.GasLimit, - GasPrice: config.Config.Client.GasPrice, - AbiVersion: config.Config.Client.Contracts.ABIVersion, + Amount: config.Client.Contracts.Amount, + GasLimit: config.Client.Contracts.GasLimit, + GasPrice: config.Client.GasPrice, + AbiVersion: config.Client.Contracts.ABIVersion, CallData: "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACDiIx1s38k5Ft5Ms6mFe/Zc9A/CVvShSYs/fnyYDBmTRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACo7j+li", - Fee: config.Config.Client.Fee, - TTL: config.Config.Client.TTL, + Fee: config.Client.Fee, + TTL: config.Client.TTL, }, wantJSON: `{"abi_version":1,"amount":0,"call_data":"cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACDiIx1s38k5Ft5Ms6mFe/Zc9A/CVvShSYs/fnyYDBmTRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACo7j+li","caller_id":"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","contract_id":"ct_2pfWWzeRzWSdm68HXZJn61KhxdsBA46wzYgvo1swkdJZij1rKm","fee":200000000000000,"gas":1000000000,"gas_price":1000000000,"nonce":2,"ttl":500}`, wantRLP: "tx_+N8rAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMCoQXv7ERRuvBfaps6b3yVUqmUUEmGvanaJbGAxkh6t034wwGGteYg9IAAggH0AIQ7msoAhDuaygC4gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAg4iMdbN/JORbeTLOphXv2XPQPwlb0oUmLP358mAwZk0QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqwDDyuQ==", diff --git a/models/tx_oracles_test.go b/models/tx_oracles_test.go index ea4ed007..8b23d752 100644 --- a/models/tx_oracles_test.go +++ b/models/tx_oracles_test.go @@ -42,7 +42,7 @@ func TestOracleTx(t *testing.T) { AccountNonce: uint64(1), QuerySpec: "query Specification", ResponseSpec: "response Specification", - QueryFee: config.Config.Client.Oracles.QueryFee, + QueryFee: config.Client.Oracles.QueryFee, OracleTTLType: 0, OracleTTLValue: uint64(100), AbiVersion: 1, @@ -61,11 +61,11 @@ func TestOracleTx(t *testing.T) { AccountNonce: uint64(17), QuerySpec: "query Specification", ResponseSpec: "response Specification", - QueryFee: config.Config.Client.Oracles.QueryFee, + QueryFee: config.Client.Oracles.QueryFee, OracleTTLType: 0, OracleTTLValue: uint64(100), AbiVersion: 0, - Fee: config.Config.Client.Fee, + Fee: config.Client.Fee, TTL: uint64(50000), }, // from the node's debug endpoint @@ -115,13 +115,13 @@ func TestOracleTx(t *testing.T) { AccountNonce: uint64(1), OracleID: "ok_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi", Query: "Are you okay?", - QueryFee: config.Config.Client.Oracles.QueryFee, - QueryTTLType: config.Config.Client.Oracles.QueryTTLType, - QueryTTLValue: config.Config.Client.Oracles.QueryTTLValue, - ResponseTTLType: config.Config.Client.Oracles.ResponseTTLType, - ResponseTTLValue: config.Config.Client.Oracles.ResponseTTLValue, - Fee: config.Config.Client.Fee, - TTL: config.Config.Client.TTL, + QueryFee: config.Client.Oracles.QueryFee, + QueryTTLType: config.Client.Oracles.QueryTTLType, + QueryTTLValue: config.Client.Oracles.QueryTTLValue, + ResponseTTLType: config.Client.Oracles.ResponseTTLType, + ResponseTTLValue: config.Client.Oracles.ResponseTTLValue, + Fee: config.Client.Fee, + TTL: config.Client.TTL, }, // from the node wantJSON: `{"fee":200000000000000,"nonce":1,"oracle_id":"ok_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","query":"Are you okay?","query_fee":0,"query_ttl":{"type":"delta","value":300},"response_ttl":{"type":"delta","value":300},"sender_id":"ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v","ttl":500}`, @@ -153,8 +153,8 @@ func TestOracleTx(t *testing.T) { Response: "Hello back", ResponseTTLType: 0, ResponseTTLValue: 100, - Fee: config.Config.Client.Fee, - TTL: config.Config.Client.TTL, + Fee: config.Client.Fee, + TTL: config.Client.TTL, }, wantJSON: `{"fee":200000000000000,"nonce":1,"oracle_id":"ok_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi","query_id":"oq_2NhMjBdKHJYnQjDbAxanmxoXiSiWDoG9bqDgk2MfK2X6AB9Bwx","response":"Hello back","response_ttl":{"type":"delta","value":100},"ttl":500}`, wantRLP: "tx_+F0YAaEEzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMBoLT1h6fjQDFn1a7j+6wVQ886V47xiFwvkbL+x2yR3J9cikhlbGxvIGJhY2sAZIa15iD0gACCAfQC7+L+",