Fetching data from json file in protractor - protractor

I am working on protractor testing framework to test the Angular Js application.
I am stuck in a scenario where I want to fetch the data
(eg: Test URL,Username,Password)from external file say Json File.
I have created one json file for this and written code to read the data from this json file but I am getting the error
as:
DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:03:10] I/launcher - Running 1 instances of WebDriver
[11:03:10] I/local - Starting selenium standalone server...
[11:03:12] I/local - Selenium standalone server started at http://10.212.134.201:59697/wd/hub
[11:03:15] E/launcher - Error: Error: Cannot find module 'E:LAM WAH EE_Testing EnviornmentDetailed_Sheet - Copy.geojson'
where Detailed_Sheet - Copy.geojson is the file where I have given the url name and username and password.
Please anyone having idea about this help me so that I will get to know where is my mistake.

Please see below example, the example assume we have two files and they are in same folder:
1) login.auth.json, its content as below:
{
"loginurl": "http://172.16.99.47:3001",
"username": "azizi#hlwe.com",
"password": "abcd#1234"
}
Note: For json file, you no need to use module.exports or exports.xxx to export the json data, you only need to write a valid json data in json file and use require() to import, then you will get the json data.
2) test.js, its content as below:
var auth = require('./login.auth.json');
describe('Opne the clinicare website by logging into the site', function() {
it('Should Add a text in username and password fields and hit login button', function() {
browser.driver.manage().window().maximize();
browser.get(auth.loginurl);
//Perform Login:UserName
element(by.model('accessCode')).sendKeys(auth.username);
//Perform Login:Password
element(by.model('password')).sendKeys(auth.password);
//Perform Login:LoginButton
element(by.css('.btn.btn-primary.pull-right')).click();
});
});

Related

How do I configure my Postman mock server response to return a date always two days in the past?

In my Postman Mock Server, I have set up a GET request to return JSON, in which the following is returned
“due_date":"2021-10-10"
What I would like is to adjust the response so that the date is returned is two days in the past. So if today is “2021-10-10”, I would like the response to contain
“due_date":"2021-10-08”
And if today is “2022-01-01”, I would like the response to contain
“due_date":"2021-12-30”
And so on. How do I set up my Postman mock server request to return such data?
I think it's a good question besides I'm curious so I made some research and found a workaround for this. It's a bit complex. I'm not sure worth it or not.
The first thing all, Postman Mock Server (in short Mock Server) cannot execute any test and pre-script so it is not capable to compute things. You need a calculation here so what are you gonna do? Well, you can define an environment for Mock Server which gives you the ability to use dynamic values in mock responses.
I will continue step by step to show the process.
1 - Open a Mock Server with an environment:
1.1 - Create a collection for the new Mock Server:
Your mock response will look like below:
{"due_date": "{{date}}"}
1.2 - Create an environment:
1.3 - Finish to create:
1.4 - When you finish, Postman creates a collection like below:
1.5 - You can test your Mock Server from this collection:
As you can see, Mock Server uses the environment variable in their response.
Now, We have to figure out how to update the environment variable.
You have to use an external service to update your environment variable. You can use Postman Monitor for this job because it can execute tests (means any code) and works like a CRON job which means you can set a Postman Monitor to update a specific environment variable every 24 hours.
2 - Open a Postman Monitor to update your environment:
2.1 - This step is pretty straightforward, create a Postman Monitor like the below configuration:
2.2 - Write a test to update the environment:
The test will look like below:
// you have to use pm.test() otherwise Postman Monitor not execute the test
const moment = require("moment");
pm.test("update date", () => {
// set date 2 days past
let startdate = moment();
const dayCount = 2;
startdate = startdate.subtract(dayCount, "days");
startdate = startdate.format("YYYY-MM-DD");
// this is not work on Postman Monitor, use Postman API like below
//pm.environment.set('date', startdate);
const data = JSON.stringify({
environment: {
values: [
{
key: "date",
value: startdate,
},
],
},
});
const environmentID = "<your-environment-id>";
// Set environment variable with Postman API
const postRequest = {
url: `https://api.getpostman.com/environments/${environmentID}`,
method: "PUT",
header: {
"Content-Type": "application/json",
"X-API-Key":
"<your-postman-api-key>",
},
body: {
mode: "raw",
raw: data,
},
};
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
// force to fail test if any error occours
if (error) pm.expect(true).to.equal(false);
});
});
You cannot change an environment variable with pm.environment when you using Postman Monitor. You should use Postman API with pm.sendRequest in your test.
You need to get a Postman API key and you need to learn your environment id. You can learn the environment id from Postman API.
To learn your Environment ID, use this endpoint: https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-b7ace502-4a5a-4f1c-8164-158811bbf236
To learn how to get a Postman API key: https://learning.postman.com/docs/developer/intro-api/#generating-a-postman-api-key
2.3 - Run Postman Monitor manually to make sure tests are working:
2.4 - As you can see Postman Monitor execute the script:
2.5 - When I check the environment, I can see the result:
You can test from browser to see results:
I have answered this question earlier but I have another solution.
You can deploy a server to update the variable from your mock environment. If you want to do it for free, just use Heroku.
I wrote a Flask app in Python and deploy it to Heroku, check below code:
from flask import Flask
import os
import json
import requests
from datetime import datetime, timedelta
app = Flask(__name__)
# the port randomly assigned and then mapped to port 80 by the Heroku
port = int(os.environ.get("PORT", 5000))
# debug mode
debug = False
#app.route('/')
def hello_world():
N_DAYS_AGO = 2
# calculate date
today = datetime.now()
n_days_ago = today - timedelta(days=N_DAYS_AGO)
n_days_ago_formatted = n_days_ago.strftime("%Y-%m-%d")
# set environment
payload = json.dumps({
"environment": {
"values": [
{
"key": "occupation",
"value": n_days_ago_formatted
}
]
}
})
postman_api_key = "<your-postman-api-key>"
headers = {
'Content-Type': 'application/json',
'X-API-Key': postman_api_key
}
environment_id = "<your-environment-id>"
url = "https://api.getpostman.com/environments/" + environment_id
r = requests.put(url, data=payload, headers=headers)
# return postman response
return r.content
if __name__ == '__main__':
app.run(debug=debug, host='0.0.0.0', port=port)
Code calculates the new date and sends it to Mock Environment. It worked, I tested it in Heroku before this answer.
When you go to your Heroku app's page the code will trigger and the date environment automatically will update, use the environment variable in your mock server to solve the problem.
You need to automate this code execution so I suggest you use UptimeRobot to ping your Heroku app 1 time a day. On every ping, your environment variable will update. Don't overuse it because Heroku has a usage quota for the free plan.
To use this code you need to learn how to deploy a Flask app on Heroku. By the way, Flask is just an option here, you can use NodeJS instead of Python, the logic will stay the same.

ECONNREFUSED during 'next build'. Works fine with 'next dev' [duplicate]

This question already has an answer here:
Fetch error when building Next.js static website in production
(1 answer)
Closed last year.
I have a very simple NextJS 9.3.5 project.
For now, it has a single pages/users and a single pages/api/users that retrieves all users from a local MongoDB table
It builds fine locally using 'next dev'
But, it fails on 'next build' with ECONNREFUSED error
page/users
import fetch from "node-fetch"
import Link from "next/link"
export async function getStaticProps({ params }) {
const res = await fetch(`http://${process.env.VERCEL_URL}/api/users`)
const users = await res.json()
return { props: { users } }
}
export default function Users({ users }) {
return (
<ul>
{users.map(user => (
<li key={user.id}>
<Link href="/user/[id]" as={`/user/${user._id}`}>
<a>{user.name}</a>
</Link>
</li>
))}
</ul>
);
}
pages/api/users
import mongoMiddleware from "../../lib/api/mongo-middleware";
import apiHandler from "../../lib/api/api-handler";
export default mongoMiddleware(async (req, res, connection, models) => {
const {
method
} = req
apiHandler(res, method, {
GET: (response) => {
models.User.find({}, (error, users) => {
if (error) {
connection.close();
response.status(500).json({ error });
} else {
connection.close();
response.status(200).json(users);
}
})
}
});
})
yarn build
yarn run v1.22.4
$ next build
Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`
> Info: Loaded env from .env
Creating an optimized production build
Compiled successfully.
> Info: Loaded env from .env
Automatically optimizing pages ..
Error occurred prerendering page "/users". Read more: https://err.sh/next.js/prerender-error:
FetchError: request to http://localhost:3000/api/users failed, reason: connect ECONNREFUSED 127.0.0.1:3000
Any ideas what is going wrong ? particularly when it works fine with 'next dev' ?
Thank you.
I tried the same few days ago and didn't work... because when we build the app, we don't have localhost available... check this part of the doc - https://nextjs.org/docs/basic-features/data-fetching#write-server-side-code-directly - that said: "You should not fetch an API route from getStaticProps..." -
(Next.js 9.3.6)
Just to be even more explicit on top of what Ricardo Canelas said:
When you do next build, Next goes over all the pages it detects that it can build statically, i.e. all pages that don't define getServerSideProps, but which possibly define getStaticProps and getStaticPaths.
To build those pages, Next calls getStaticPaths to decide which pages you want to build, and then getStaticProps to get the actual data needed to build the page.
Now, if in either of getStaticPaths or getStaticProps you do an API call, e.g. to a JSON backend REST server, then this will get called by next build.
However, if you've integrated both front and backend nicely into a single server, chances are that you have just quit your development server (next dev) and are now trying out a build to see if things still work as sanity check before deployment.
So in that case, the build will try to access your server, and it won't be running, so you get an error like that.
The correct approach is, instead of going through the REST API, you should just do database queries directly from getStaticPaths or getStaticProps. That code never gets run on the client anyways, only server, to it will also be slightly more efficient than doing a useless trip to the API, which then calls the database indirectly. I have a demo that does that here: https://github.com/cirosantilli/node-express-sequelize-nextjs-realworld-example-app/blob/b34c137a9d150466f3e4136b8d1feaa628a71a65/lib/article.ts#L4
export const getStaticPathsArticle: GetStaticPaths = async () => {
return {
fallback: true,
paths: (await sequelize.models.Article.findAll()).map(
article => {
return {
params: {
pid: article.slug,
}
}
}
),
}
}
Note how on that example, both getStaticPaths and getStaticProps (here generalized HoC's for reuse, see also: Module not found: Can't resolve 'fs' in Next.js application ) do direct database queries via sequelize ORM, and don't do any HTTP calls to the external server API.
You should then only do client API calls from the React components on the browser after the initial pages load (i.e. from useEffect et al.), not from getStaticPaths or getStaticProps. BTW, note that as mentioned at: What is the difference between fallback false vs true vs blocking of getStaticPaths with and without revalidate in Next.js SSR/ISR? reducing client calls as much as possible and prerendering on server greatly reduces application complexity.

Error while deploying Aion dApp through frontend : fs.readFileSync is not a function

I was deploying my java contract to the Mastery network through the frontend by using a MERN stack app and came across the following error while compiling:
Module not found: Error: Can't resolve 'fs' in '/home/parina/Documents/aion-counter/node_modules/aion-web3-eth/src'
To rectify this, I added
node: {
fs: "empty"
},
to my webpack.config.js file.
After this, I was successfully able to compile my project and start the server but on opening the project in the browser, the contract was not deployed and I got the following error in the console:
TypeError: fs.readFileSync is not a function at Contract.deploy (index.js?60f4:244) at _callee$ (Main.js?1523:40) at tryCatch (runtime.js?280d:65) at Generator.invoke [as _invoke] (runtime.js?280d:303) at Generator.prototype.<computed> [as next] (runtime.js?280d:117) at step (Main.js?1523:9) at eval (Main.js?1523:9) at new Promise (<anonymous>) at eval (Main.js?1523:9) at deploy (Main.js?1523:19)
After searching on various forums, I found out that fs is not supposed to be used on the frontend and I was suggested alternatives to it. But it here it is being used by the Aion node modules and not directly and therefore I can’t seem to find the way around it.
As you mentioned since, fs is a server-side module, the file can be uploaded (through react or whatever is the clientside module) to the server and executed server-side and response returned to the client.
So I would suggest to get the encoded byte code of the jar along with the deployment arguments and set the transaction data field to the encoded data.
For example, assuming you are deploying the counter sample contract(https://docs.aion.network/docs/deploy-a-contract#section-example-script):
let data = "0x00001bab504b0304140008080800e582b14e000000000000000000000000140004004d4554412d494e462f4d414e49464553542e4d46feca0000f34dcccb4c4b2d2ed10d4b2d2acecccfb35230d433e0e5f24dccccd375ce492c2eb65248040aeba596640015e879a4e6e4e43b96e5f272f1720100504b0708d0dfc09e3b0000003b000000504b0304140008080800e582b14e0000000000000000000000001a00000061696f6e2f6574686572732f48656c6c6f41766d2e636c61737385535b53d35010fe0e141242b8ca1d6f08680a48bce205bcb405a450402d82506f87f6580269a2695a87f1d91fe17ff00165a674d4f1d519ff938e7bdac208c38c79c84976f7dbddefdb3dbffe7cfd01600c2f18dab8e53aa6f03784973567846dbba17c46016368dee4796edadc499b8beb9b22e92ba86668d88f19956e861af79d233cb2c7783e638652294f64b3e3644fba39c767605186da09cbb1fcbb0cd546705987867a0d01e854c272929ec808c78fc86899276044658c8aba3a54a199622aaea80ce5599152d17aa8b9b8ef594e5a411b839a167e78db175999279808ebe840a786767411d11222c3fd0d336ca5a394322d3c053d0c4a9edb39b1f89aa1db980dc68e8b1bd77112a734f4e23443bdefca2221cfe3db3aceca0abde86368940a846d37b995dce096a3a09f18db6e9a2a188970222c790de2bc86015c2006297194fb3ed549714075a84c2a521693f42339d589a45d11b44efab86d4b7493113c34031d262ec9629775d44291725e65e877bdb4599ab98ccd6585675beb265fb7cc50384a85dd9454e53af54ca927b9cf75dc900c077093866a945968b8add1fa8c97591064d11115a574dcc145e9a4ee021992e120669e96cc4d2df08ca06118159dff9920351c425842232a1a696bc4db1cb76994ed46ece82a8e07d7744ce3819ced8c8e463469446f56455047b0fc33af6244c7886ca60a0fff437ccaa9107f4ced0ae73025c93b5adaa6253cd110c73235e789bcf07c1d4fe5320f6095d84608451721eef3e4d63c7fb3c4d76dfad7e26ece4b8a69cb16e8a3560274f3aa48411a097d6972d3e9ac0593f782de09fa6ba193d15933b48786cf904f9d2459710fa2bae4eefe82969e57bb68693d514077cf8722ce1470ae08631f123c1e929290e1e321245805d25c020001827c2a7da9183d68f1206111577671ed1bc6568bb8b58789b9a102ee5181fd84f7d15981bc2748159d89c3c193b1e19f50aabfab3bc3ad5305443fa265689572bc5c2962ae6c8e1d312f94cd8b25b356c4a32256768a58633b949ee119bd1b11f88d2e05630ada3b3aa40ccf4bc2d7fc05504b0708eae6949b02030000fd040000504b0304140008080800e582b14e0000000000000000000000002b0000006f72672f61696f6e2f61766d2f757365726c69622f6162692f414249457863657074696f6e2e636c6173734d8e3d4b03411086df399353ce4413c1269d85e007b89d8d12d0a810b13278fd242ec7c86657f6f6827fcb4ab0f007f8a3c48929cc14f3f1ce3b0ff3fdf3f905e01c7dc26188956109def0626e9ada462753c3533157d7e3dbb7997d4dbadc0411062fbc60e3d857e6b1f149e6766dbf41e8af5f9c2dcd849e02855d6963ade2d3f88640f76dac4299f9a5784943c2fed1c33f7e92a2f8eae2b8eca0c07681163a84ee28f83ab14f25bbc6125aa3f0aca5988426ceec9d388b0364ea553006c8a14f6347a70c5bdad112a57957953dd532adf9c9e907baefab67d0fbf3b67f01504b07080969797ee00000001e010000504b0304140008080800e582b14e000000000000000000000000290000006f72672f61696f6e2f61766d2f757365726c69622f6162692f414249456e636f6465722e636c6173739598df771b4715c7ef4a2bed5a7192956c494e223b92d31fb27e4489da2885d4054b8a8b1c3b2948a44d5ca8d7f6da96ab48aeb44ee31692425d28014a43e92f28a4fc38f8151ea02e04c1034fbcf3c039bc7178e13fe09c52716776a59ddd952a350ff6ceccbd773edfb9777e387ffbf80f4d00c8c0cf393851abafa7e472ad9a92af5f4b6d37947aa5bc9c9297cba9996ce17c75a5b6aad405e0389036e5eb72aa2257d753979637951555002707870dab93c48083a1ec95d2f96716668a1738e00a4e9ca7c581fbd172b5ac3ec681333a75791886c0e3011e0e707050a1ce97aa4a764755387045b3538b599ccde8afd52a8a5c254357e99063312b8097035fc724b721d7e51555a913a31c353ad4192c6ed4ea2a19285a0217aaaab2aef914e890c1325fabae93fe39ec7781f6afc5069dadd4641a74967a1e36d6868e08701cadd7c867a986f364cb6a83031ead0bc31081490f84e104ba75e2e56bdbcb152a3faf511a01b521011ec4de55fa5daa11be76ccfcd4dc304c41cc035188b3ab421674a65e977770f9a38bdab2deff89d9beb1a26ca93828408a8330f50d5794eababa11beb6dd50c36b65355cae86d3e1650cdd10e13407fee8bc815a54ebe5eafa392dc30f79e0143c6c9252dc69a8ca35013258253289be52db42ba181b43abad73852e5d0512f811f88c07cec267716a6b891862db85725500acb9a0bd500c53ad5c46cce5620c6b45e3b7168d61a0958ecf543ac6e89c253aad0e6358ab9e514b1918e35a311865a22d3007816eab6ea91bad5b808b1c88eb8a4aaa81d60bda0dc313f0450f5c822fb1fb616675b5ae34d0c61b9d27d5a1b7b5c007981e012e63875aeb14d8303c45e23d095748d96846e1e7e546b8b616deae2a37b6307dcaaa5e4a222cb292d379a64e85e8222dd46148c2490f38e019a459abc8aaaa54d3797ace50fd43c4aea059cab04c2c57f06c59242783c2261ca39b6a834c7095ba3d0ad3c4ad4cddb04e9ee5e008e366ad14e298a38e9f8719e258a38e39019e63cb239d67eb873815a9531672c4699b3a150578de0c69ae2ae256a06e79384fdc5ea46e0501be6e9e8bad26e2344b9dbe0005e2f40dea342bc0cbe6e5660a94f8cc519f59789cf87c9bfacc09f01dac31c6c75497c42b4fbde6e002f1fa3ef5ca0bf0037626adfe749f6074b16bc50ec33c2c90186fe02ee96222c09bac64bdb6f4a03e0c6a29d46128c19749bc77f1fc358f0af0133ce273b56a4395abea65b9b28d95c2e7303076175579e5d90579ab24d363d853ac6dd75794d9724581d3188dc7f39f83a3e006bc0ae1a7d872800813f8136f32ecf919f678f13787bf5db10f60f8b7f4ca18828370481f3e0a4e340738e4ba27cec79d7c29ce1f2dc57fa3db1d0649b79bd3ed829a9d8bd8bd0b02bf07bcf38ee6c0c15dfc1901470b7ce0e004f2137f702dc2459b4ed2c46d022330aac78da30812f7b89bc67593b892f882175a3731aceba8fed106f243a0bba3d0c7310863ba634e773c2b5247913a8e198e92d4fe763301056bc023b8745ac09770fdc97b429586ee890b09a7e42e25f809e9911747e1d8ad57ef9412ae09e954a7e19e90a29d863021853b0d71421aeb3424b4938c161a8a464b9c687fb669c631eb1a4d01e5119a69226f721fee9b8e3b25b23a2146648811196244862c22ef8707f4b0afa048f2e4d8a1221fd8874416958aa834c22a8db04a23acd208ab3462521a31298d989446ac4af104d691540422897c8a8bfd1a46b5ba94d2a854f296f620176b7a6fb57e0507ff08a7aef8d21fc0993fc79aae257e49b3f3a25dacc9140c9ad3af9833ee8e35f7e11c53d31e7006bc1f4192d4f01039a275820f71adc91e7cce46e04382a73f99c0d78bc039ed7e2c146bfe028ec5c763a1878c5db6ebe0769ddc5eebdf0c5a06dc01efc710a53bab85bb9d17e073da36eb6c3ea34bdb80ff454143e4c2d065bcafcbb8659331823236bbcad830848cf415f22011f2b06131ce2f615b6b50518ebdd63f1851878127a2623aed14d2e24dd597767410dad1c168cf5868cf7c2a5abc2075dabfe8b4776db47ea4bddd8d566068fd7d691f27b4278dbd4d694f1afb7bdc45db861a3769336af8bdd687bdd514500ddec29a1aee009e0244cd7f6c6a02a8e6efddd448222327d057ce1d2227651c299a9e9471ac688252c6d1a2294a19c74b7c5ca01d634687483b24a343d27c44a6873ae94dba30e25eab665f98b8be306fe0c2e093464ff35f7159c8f1f84bdbc20471615eeb97e660df75b9100b9dc2c33cc3c7c7fdbc29dbd864938d4d36d77ede9ceadff54ef5022ac2a713936a77d7548f0d94eab1fea98e854ee33d721625057873c6b16d4a38b64df9c6b629ddd836651bdbe664638739d701fed3a51adf837aaad730d1e482bd605b98082e4c26f67b282e2498733e824309762112fa4224f0a649586e9a2170043e82b476d1e09b519f73539f73c636e724ce99c039af2e48e144f3ae9e90a74942a48866374966e2ad3305f14efb1fbea770aa96f6527b92cc4a10be025fd5e77d592feb27c8bc47dcccbca75108bd6733c274acf927f05d7466783f4ff21a4ae26f3f9fde87a522f94e3797a67779bcb7fe950c49de7d589d373d17f9632dbc8f5c022e2c3e12d7f0ad7abc855408b4d6065a878dc1807c7d8036ed40bede40152b50a50d740daa83018df401dab2038df406aa5b81ea6da006be8606021aed0374dd0e34da1be88615e8461b68075e180cc8df07e86b76207f6fa09b56a09b6da05bf84e1f0828d807e89b76a0606fa05d2bd06e1be815f8d66040813e40afda8102bd816e5b816eb781be0bdf1b0c68ac0fd06b76a0b1de40af5b815e6f03dd811f0e0614e903f4233b50a437d05b56a0b7da406fc33b83014df601fab11d68b237d07b56a0f734200ff94f261d684bbfae8bc7ee8917934ec448f2a152d2c55cc14977fb0a1632bc33e3f2bb08d48998df95765232579adc11fad75286df7521db3f9306d30170b49f0be4efc2f7c91ff6e0fa3f504b070831a65f2973080000b7170000504b0304140008080800e582b14e000000000000000000000000290000006f72672f61696f6e2f61766d2f757365726c69622f6162692f4142494465636f6465722e636c617373ad9a0b7c1c451dc7ff93bbcb6e2edbf6f26cda24ed252d36495b425b0a96b69034d7684a9a02498b092adde6b6c995cb6dbd6c4aab88a01451f1d5aa8020d4021690a71652a1147c2be25b514114df8a5a8ae203acc4ffccceeecdec6ddae54c3f4d2f3b3bf3ffffbef3f8cdcc7dfac4ab0f1f018033c83c02f3ccec50ab9e3233adfa8e91d6b151239b4e6d69d5b7a45adbd774258c4133696415200462dbf41d7a6b5acf0cb56ed8b2cd18b41408119891ab752aad40a0644d7fdfda8bd7b7f79e4b80748530cf8453d8db35b09616a804c249ddc2ca4517ad21a06e374753164a2050bc2a954959671388345db4a67913815053f3260da6432c0a6128d3a014b41228820a0da681427fab4265492660bd610d9bc91e7dc42050d9d4dc9dd3db6b655399a195a8d6aeb92163d8451acc829a2846992df1d92f15a8436d4386d53b6c662d26a51715624157c67eec22a0e063b7991962cfeb10943e1b99216b18199bba6895534ed4c36b770e1adb29bb02af23b02a81bd12df9a32d2c978d23446e319d38a0feb3b8cb89131c78686e35b7659589a36b65a71cb8c670d3d19d733713d9bd5779daa421381aaa67c6ebb075ba2b000166a3007e652e2c504ce2e209b359c1a75f3b51298e6f6e81aaccc7a0147b47c70d818bca4672c9d5e3bb2ddda45f368b08c0e62119c4ee0ac42305921263d8340738fb1d38a1b6963c4c858f154269eccc54bd9d1dceaaf77e707d5689a6943cf309903045617a6c30e82b157115814488adb026776b9aba66358cfea839691657a3a08ac2c48cf289d9e181bfbbd25881aa77e82c0f4dc7ab0e778aeab708e1b43545a21b304e764ca6e8f79de486071005d6293751ac4a181ce966e718ad90badb0d993c6b6187943c0d9c3ab9faf4123cca3427ac5deea4c9bba6d019d858eda561a02335c1870d49cfafde862b915ce842870118ac3de5b93b246fb4c2e8eba4fa7066f81b746e1cd70b1687e09736c4bda5eac89024d076bd218286890c0c220006e0343f25a5b8b0238b031dae93683a330dcb4ae39a1410ab64561182e11570ff59b766a44b45633dd476632d7599fcad806dc6966ed8d4a03d3b69eed045a835a876b72590de6c329b4b9256f12bb462d6344811d68faaceea0b91db5b488066ce75fd9e553d4455d7927ec8ac2a5f0760534b46eaf4d09740374ab1c50e05d4899ef1f42457491d383200e3a6d5dcef7d0141d0aec265021db82101e57c169813dc60dfd3e1aba57810f8890dc6084e0b8572e7b2d46e1c6ff308ddfa5c047c5f941cd4208be2ee0d8d339e806fe380dbc4e81ebc43e61eb4b88dc19b04fd80a7643df4843772af0293cac7816a6101b97e792e08bcb0dfe691a3ca1c0ad01d7e6283b2860c3db0bb50337c20102e7147aae7083dc490f2c33a2500f9f15f7a4f664326b8c8ea295e1f18e1ea678c1caa03b8c6ed7c70cf715bcb1e5623c40a05450a1c0e7a370902ace0de8d2846053111c50ea537593f814aba6c121dbacbe40606990b15b9a90fdea110d462043233c4a20de618e61655ad3d6e46da0c263b80fa02c05be287a0b0a974c886947175a1e5492ddda55f5550dde099753555fc73bc724aac4362a7c930943d3fb1681598230afed3169e87b670694966f7ddfd5e04a783715f77d3caefb8bf3b452e1874c1e1ae68f45575b9a102d9349eb0d666b34896c9b3fd3e0bd700d95f50c81067f59420b159e6592d0687f290fa56cb54c5457f0a1f4baed6f34f8207c88cafadda44329b551e10f4c183af49fe4c521783453b52ef89c977cfaaf1aec858f51492f4c3ae7730d547891e94163ffbb3c76a2b533419dc1c74eb6f77f6970037c922a7a79d2b1135aa8f01f26093784ff12a81624495b02d39408b8c56306795b2044835b601f8a2221962da190883820f67d91e7aac25c7e77e840fb91ede46ee21202737dfa40aca59252dc647d322a649a3848dc6cb9c8181529ef04c18e10dcc55d85651adc03f7d2aea9f01d2f4f0b9554e1915b4ead90997812e8cba68c24dd2f78cbad597304513378178e9bd9b841efc382244c3dabc08b68266eb26d0343d412e8f87f42b8dd508fd7ad0e33336ae9196b939e1ea347f00ec4c0e25e4bc74d4bdfdea7b39379b4d71ccb0e1a9da9b4010d38cdc300f8331b8a817e5b34179f8a40c5e712e1992e8752d0d8efd3b01ce0142074a7c71a717caac5f222fc9cd1320ee52d0b1f84ca96d08350fd00d03f686950c32baee015eb49cb41a8bc1db410fd3cb20f54d27d00d49687a0b67be1fdb41169c07fa3102a0b1f87b082078a22fa05881b26ccc22ca6adf1a77a594cddb97755adf318debcac0c262ebf62efaa967e7c8c6c4631b577333545f482cac3e83ccc46314c7e14a930e25758cc0bed748a940eafa13cdde31001fa2dda4131ddeeb6b99e7cbbaf8ca9bb72a511dfd262df52c5b754f52d8df98788b931da184c4ca53473efe134f3e9c8339a0b9085d2ac6023489b2623fb61da23b0a0bfbc791c163d8673e1d4d5b99775b5c3ceebd3e8ebbabbdd6156a0a8e638cc21385596c052777022f80c702ec659ee93e34c9683aaa63207c254e6b2f02dfced0abfb7b98c38ee75f518fe2c58c9d3a579bade49d2adf60b1871d29de3f7f60650c207201c1241c375f5d56d14b40dda79e64d3c739b9cb9d8c9dce117bbd8c9bcd6e9ea3df9749dee82d9c8739cf35a72287939f253bcc15d4c93a4509d145d7e295427c5b93cc5fafc143dee02ba90a7689753c44a9c1ce7f9e588b97d75014fd2778f98a47e0e06dd88c36027e9e7493a26e178936f0eb7af061c9043b0f95e8985a6d1610b4f33c0d324266349fae6713b6cabc37208d2f7e5e1e04582e7b9999bce4e96671cde46ba73f6b3741fc405f78995ed8358ce310fa0386ffe3227ff28cb1f1e87b1d575875537e6c250dd2178076b52475b08665e09a1e3b03c3267826e3b0afd7b19db1df07ac1b53e4d17087e5e13446bb9476b5f9ed6725fade1eed0d9f575fb61fec2fac9166cdf55217260e259417b1b1473eda5743742ed57101cbd09dc97728fec63828e825b14621f2fe3e64ae84d8573eec331a19c6341382b3c9ced799c150ee7558c3362734638671972527bd8c8a08e0950b320ec81ba9a42bd0ce5a8162f305ced2d5cad15446da5476d5b9eda4a47edfb45b5255c6dcc56bb89897df18462afb5c596a158bcd61422b6eaa462ab1cb11f6162155b6c5412bb7e4300b17b7262f1c253c83ca83ee93ca876c47e82898da9b6da52496ddf792750ab71b5d7e7d4e26588abddcfd55e1a44ed4c8fda8e3cb5331db537895d5bccc556d85d8b267a3ed37bf484bd7bb3adb712f5e23d89ebbd95eb0de47c352775be1a47ef7ea97715493075e30b4e20d8e9e0db728267b987e367b8e0fb83086ef008be2c4f708323f833ce4ee239d2dce1774a735edec5ce6887d51e27e9628fb33f02f5fd8bc7e1ee6e0934c240671e873a74c2f9dce7eb99cfe3358d831ee47bd2750ea884d9286236eec30b858b492f098379a08d0ee8fd32682ceec07c8ebe88c50fabeb9dd88b42b1b883138bdb3c07fb178dc383220fceafe573f068ba4041cd041e82714e70940fd51d9ce061cf509d26322c11862e22eeb2c5f6d025f388b045cde45bef61c1381f85cb84e5fd101ce9b597f70198dec32a3f4e2b231281abe07ab8111670b445a01c87b591e692dca4fc129d94651378ca0ff167200a2c7805af6104be0c5f990af6f2c2d8ddadfc6b12fb1512fb37bcec4f04677fd2c3fea4c8fe6df8ce54b05714c6ee6eefdf93d8af96d87fe065ff5170f6a73cec4f89ec3f819f4e057b6561ecee61e16989fd5a89fde75ef65f04677fcec3fe9cc8fe2bf8f554b05715c6ee9e3d7e2bb1ef91d87fef65ff6370f6e73deccf8bec7f86bf4c057b7561ecee51e6a8c47ebdc47ecccbfeb7e0ec2f79d85f12d9ff01ff9c0af69985b1bb07a37f4bec374becaf78d98f07677fd5c3feaac83e4180b3bfc0d9ef2c84bdc6c36e0463c743d6748a53418a24f8db4478129e7cc1efc603eb4d79f051179e14cbf0f89c83270a5139fc310e7f5721f00d1ef8adc1e01b5cf8a8045f2f8d7cad0b3fa3c7aead05a79feea19feed097629b19243615f48d85d137baf4e512fd4169e82bf3e8ab83d3d778e86b72f445f47fb971fa657838a55fcde47d49cdf5cda6191f10bf7329a35f909b6e80561e60b674e8e6adebe4d6587316363e74a2c6c56ee3393e8d096904fad56ce47f504b0708f119f71edb0b00001e2a0000504b01021400140008080800e582b14ed0dfc09e3b0000003b0000001400040000000000000000000000000000004d4554412d494e462f4d414e49464553542e4d46feca0000504b01021400140008080800e582b14eeae6949b02030000fd0400001a000000000000000000000000008100000061696f6e2f6574686572732f48656c6c6f41766d2e636c617373504b01021400140008080800e582b14e0969797ee00000001e0100002b00000000000000000000000000cb0300006f72672f61696f6e2f61766d2f757365726c69622f6162692f414249457863657074696f6e2e636c617373504b01021400140008080800e582b14e31a65f2973080000b71700002900000000000000000000000000040500006f72672f61696f6e2f61766d2f757365726c69622f6162692f414249456e636f6465722e636c617373504b01021400140008080800e582b14ef119f71edb0b00001e2a00002900000000000000000000000000ce0d00006f72672f61696f6e2f61766d2f757365726c69622f6162692f4142494465636f6465722e636c617373504b0506000000000500050095010000001a00000000000000142100117468697320697320736f20737475706964";
const Tx = {
from: "Your address",
data: data,
gasPrice: 10000000000,
gas: 5000000,
type: '0x2' //AVM java contract deployment
};
This can be your transaction object.
The issue got resolved here:
https://github.com/aionnetwork/aion_web3/issues/78#issuecomment-513938605
Since fs cannot be used on the client-side, I shifted the deployment function in my MERN dApp on the server-side while doing the rest of the interactions on the client-side.

How to create and call cloud code functions on parse-server?

I'm trying to run some very basic cloud code function on my parse-server and I get the same error every time: 141 Invalid function. I'm just adding a main.js file with my function in the cloud directory and trying to call it using Postman, but it looks like the file is not even called.
I've tried locally and on a docker, if the function exist or not I get the same result, and tried restarting the docker container after adding the code. I also tried adding a body to the request with parameters like master and functionName.
Here's my cloud code function (cloud/main.js):
Parse.Cloud.define('hello', function(req, res) {
return "function called";
});
Calling the function with a POST request on https://myurl/parse/functions/hello
and getting:
{
"code": 141,
"error": "Invalid function: \"hello\""
}
The response object has been removed from Parse Server Cloud Code post v3.0.0.
Your Cloud Code function should look like this...
Parse.Cloud.define("hello", async (request) => {
return "function called";
});
Please read the migration guide for more details on updating your cloud code to v3.0.0 or above.

gcloud deploy function error code 3

I'm doing the tutorial of basic fulfillment and conversation setup of api.ai tutorial to make a bot for facebook messenger, and when I try to deploy the function with the command:
gcloud beta functions deploy testBot --stage-bucket testbot-e9bc4.appspot.com --trigger-http
(where 'testBot' is the name of the project and 'testbot-e9bc4.appspot.com' is the bucket_name, I thought..)
It return the following error message:
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Source code size exceeds the limit
I've searched but not found any answer, I don't know where is the error.
this is the JS file that appear in the tutorial:
/
HTTP Cloud Function.
#param {Object} req Cloud Function request context.
#param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working
res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
res.send(JSON.stringify({ "speech": response, "displayText": response
//"speech" is the spoken version of the response, "displayText" is the visual version
}));
};
Make sure you are in the correct directory where your go code resides before executing gcloud beta functions deploy testBot --stage-bucket testbot-e9bc4.appspot.com --trigger-http command.
I was working in the express project. In my case, I mistakenly installed the #google/storage package in devDependencies instead of dependencies. I unable to notice as I tested the project in debug mode using mocha. So in debug, it is able to find that package in devDependencies but on deploy function, it tries to find in dependencies in package.json but unable to find there.
Open command prompt at the location where index.js was created and run the above gcloud command.