I'm writing test for my solidity project. Using Truffle #5.3.5. So when running truffle test It generates 10 accounts with 100 ETH (I believe it runs with ganache in the background).
The problem lies with I need an account that starts with 0 ETH. I have looked through the docs and haven't seen a solution to this.
I have tried using the ethers library to generate a new wallet. but it the test node doesn't recognize address (rather it doesn't know the private key for that address).
Is there a way to do this within the truffle testing environment.
contract("TreasuryContract", ([ treasurer, managerRewardAddress, employeeRewardAddress ]) =>
{...})
The test itself isn't really relative to the question but the above is the method I'm using to get the accounts. (this all works fine).
I was just hoping for an easy way to have an account that the test recognizes that start with 0 ETH
In Ganache configuration, accounts & keys, you can change de account default balance and put it in 0.
Bests
Related
I have the below code
const SimpleStorageFactory = await ethers.getContractFactory(
"SimpleStorage"
)
const simpleStorage = await SimpleStorageFactory.deploy()
await simpleStorage.deployed()
await simpleStorage.deployTransaction.wait(6)
I understand that hardhat's getContractFactory is automatically supplied the abi, binary and specified private key for signing transactions. After this is done I am assuming that SimpleStorageFactory.deploy() is the same as in ethers and deploys the contract to the blockchain, and then I am waiting 6 network confirmations. However, I am confused why hardhat has await simpleStorage.deployed() and what this does?
I have tried reading the documentation on hardhat but have not found an answer to this.
The await simpleStorage.deployed() line of code is waiting for the SimpleStorage contract to be deployed to the Ethereum network. When a contract is deployed, it is uploaded to the network and made available for interaction.
The deployed() method is a Promise that returns a ContractReceipt object, which contains information about the deployment transaction, such as the transaction hash, block number, and contract address.
This method is useful because it allows you to ensure that the contract has been deployed and is available for interaction before you try to call any of its methods or access its state. Without this line, the rest of the code might execute before the contract is fully deployed, which could result in errors.
The await simpleStorage.deployTransaction.wait(6) line of code is waiting for the deployment transaction to be included in six blocks on the Ethereum blockchain. This is done to ensure that the transaction has sufficient confirmations, which helps to ensure the transaction will not be reversed.
This hardhat plugin adds a mechanism to deploy contracts to any network, keeping track of them and replicating the same environment for testing.
I have a total of 7 machines in a test setup that run test scripts between any two combinations of those machines. These scripts require the IP address of the machines involved in the test run. I'd like to store each machine's IP address in a variable to not only make it easier to reference and call in our JavaScript test scripts, but also design the variables so that they'll be set by pinging the machine to get an up to date version of said address. I don't expect them to change, but you never know what might happen and this would allow to completely ignore them for the most part.
We're using Squish as our IDE for running JavaScript test scripts and Squish has an in house function OS.system that lets you run the command prompt.
It's probably obvious that I can't just use something like const pc1 = OS.system("ping pc-name") since ping gives a return far more than just the IP address.
I was wondering if there was a simpler way to pass a machine's ip address to a JavaScript variable.
I don't know which OS you are using but you can do something like that in Linux bash:
ping -c 1 google.de | grep PING | awk '{print $3}'
But I would recommend you to use a library for that.
You can take a look at this: (node.js)
https://nodejs.org/api/dns.html
Trying to set up MongoDB for my Node.JS application. I running this command:
mongo "mongodb+srv://cluster0-gjc2u.mongodb.net/test" --username <myusername>
And getting this response every single time.
MongoDB shell version v4.2.1
Enter password:
connecting to: mongodb://cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-12-07T12:14:39.630-0600 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.630-0600 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.631-0600 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-gjc2u.mongodb.net:27017
2019-12-07T12:14:39.631-0600 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:40.259-0600 I NETWORK [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for Cluster0-shard-0 is Cluster0-shard-0/cluster0-shard-00-00-gjc2u.mongodb.net:27017,cluster0-shard-00-01-gjc2u.mongodb.net:27017,cluster0-shard-00-02-gjc2u.mongodb.net:27017
2019-12-07T12:14:40.799-0600 I NETWORK [js] Marking host cluster0-shard-00-00-gjc2u.mongodb.net:27017 as failed :: caused by :: Location40659: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb.net:27017], err: AuthenticationFailed: bad auth Authentication failed.
*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
2019-12-07T12:14:40.800-0600 E QUERY [js] Error: can't connect to new replica set master [cluster0-shard-00-00-gjc2u.mongodb.net:27017], err: AuthenticationFailed: bad auth Authentication failed. :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2019-12-07T12:14:40.803-0600 F - [main] exception: connect failed
2019-12-07T12:14:40.804-0600 E - [main] exiting with code 1
I have whitelisted my IP address and made sure everything is in order. What could be causing this problem and how could I fix it? Why would this problem be occurring?
What I tried was:
Create new user
Made sure the username and password for my mongoURI when connecting my application is the same as the username and password for when I connect with the mongo shell.
Run your connection string in your command line in your application.
I realise that "just wait a bit" isn't a terribly constructive answer, but I had the same issue and no luck in finding a solution, so left it for a couple hours and came back to find it working perfectly.
The text that says your change has been deployed is misleading. Not sure why it takes several hours to kick in, but for reference I found this when using the M0 Sandbox cluster tier.
So you have to take care of 2 things.
1) First off, having mongodb in your $PATH, create a .bash_profile under the home folder if you don't have it already, then insert the following.(For Ubuntu)
export PATH="$PATH:/usr/bin/mongo"
Make sure you place the location of mongo on your computer. If you don't know the location, type whereis mongo on the terminal.
After saving, type source ~/.bashrc in the terminal.
2) Lastly, copy the connect link from the mongodb atlas, and when asked for username and password
please provide the credentials set to access the database not the mongdb atlas account.
This resolution might be specific for the mLabs to MongoDB Atlas migration tool provided by Cloud MongoDB.
My resolution was to:
Re-create the user with the same user name
Change from spesific mLabs grants to Atlas built-in roles
Set new credentials, I also avoided using special chars.
Good luck!
Create a simple password which doesn't have any special characters, it only includes alphabets and numbers.
I wasn't able to access but changing password worked for me.
I am trying to learn how to process payments with Square, and am trying to run their examples from GitHub to get a feel regarding how to structure the payments application. I built the node example from here: https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/node_payment using npm install and npm build to get the app up and running.
I am using "4532759734545858" for the card number, "123" for CVV, "0120" for expiration, and "94103" for the zip. I got the card number from here: https://docs.connect.squareup.com/articles/using-sandbox where it states that this is a good number to use for a Visa sandbox.
Also, I have updated the config.json with properties from my developer settings.
When trying to process a payment a get a DOM element that says "Card Declined" without further specifying the error. Is there something I can do to parse the error?
Based on the documentation at: https://docs.connect.squareup.com/articles/using-sandbox#generatingerrorstates it seems the amount_money field of the request is not being populated, but I am having trouble confirming.
Ideally I would like to get to a point where I can add a card as a hash value to my db and use it for recurring billing...
That "card declined" message is actually the error you get back from Square's APIs. You can play around with the error messaging in the app.js file and the `error.jade. Try error.catagory, code, detail.
Keep in mind that this is just a sample app, to show that you can use the APIs with node.js, you probably don't want to use this code in your production system.
Suppose I want to execute 'db.things.insert({colors : ["blue", "black"]})' in browser. I can execute it in the Mongodb -shell but not yet understanding how to execute it like: open up the Google Chrome Console, initialize the DB -object with some connection and execute the command. Does there exist some plugin? Sorry I am totally new to MongoDB, trying to test just things fast with Browser shell. How can I do the initialization like that?
Trial 0: perhaps with REST -interface?
I have enabled the REST with "$ echo 'rest=true' > /etc/mongodb.conf;
$ sudo restart mongodb", works in Ubuntu. More about rest
here, not sure
yet whether needed here but perhaps with some POST/REST -method I can
do the init.
Trial 1: Oreilly's book about MongoDB and 50 Tips (page 47)
The book has some example
> db = connect ("ny1a:27017/foo")
> db = connect ("ny1a:27017/admin")
so now
> db=connect("localhost:27017/test")
ReferenceError: connect is not defined
Yes because I need to source the connect -command, some further examples here, where can I get it?
P.s. I am studying this tutorial here.
You cannot simply access mongodb from the browser console. Your browser is a client, and there isn't (as far as I know) a javascript client-side library. Any javascript library you will find will most likely be for Node.js (server).
The mongo console is its own type of compiled client. The native language is javascript, but those commands only pertain to the actual mongo command shell. connect is a command for the mongo command shell.
Enabling REST starts a port on your mongod that will accept REST http communication. You get a browser page here: http://localhost:28017/
This is a very basic page displaying data, but you can further run queries yourself. See http://www.mongodb.org/display/DOCS/Http+Interface#HttpInterface-SimpleRESTInterface
Note, the REST interface is READ ONLY. You cannot insert.
That being said, you need a proper driver for your language of choice.