Flight Surety Project FAQ — Udacity Blockchain

Alvaro Andres Pinzon Cortes
14 min readMar 13, 2019

--

🏆 Ringaile´s amazing Udacity blockchain project | FlightSurety Project Competition

🏆 Stefanel´s amazing Udacity blockchain project | FlightSurety Project Competition

  1. For the flightsurety project can a passenger purchase insurance for more than one flight?

Yes

2. I get the following error while testing

 truffle(develop)> test ./test/flightSurety.js Using network ‘develop’.Error: FlightSuretyApp contract constructor expected 1 arguments, received 0 at C:\Users\avant\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-contract\contract.js:390:1 at new Promise (<anonymous>) at C:\Users\avant\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-contract\contract.js:374:1 at process._tickCallback (internal/process/next_tick.js:68:7) truffle(develop)> ‘’’

Yes you need to pass the address of the Data contract to FlightSuretyApp in testConfig.js

let flightSuretyData = await FlightSuretyData.new(); 
let flightSuretyApp = await FlightSuretyApp.new(flightSuretyData.address);

3. I am using openzeppelin 2.2.0 that uses solidity 0.5.2, but the lastest version of truffle (5.0.8) uses solidity 0.5.0, how to solve this issue?

These are my suggestions

1) In the truffle configuration file put the version of the compiler that you need to use, in this case 0.5.2

https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration

2) Use a version of open-zeppelin that uses solidity 0.5.0. In here you can find all of the versions https://github.com/OpenZeppelin/openzeppelin-solidity/releases

When you find it install it like this: npm i openzeppelin-solidity@<version>

4. I am getting an error . It says sender does not have enough funds to send tx.

One option is that you are using an address that is not generated using the mnemonic that you are using with Ganache, therefore that address is never funded. The solution is then to the mnemonic to match the address or to change the address to match the mnemonic.

Second option. You are using an account generated using the mnemonic, but the account that you are using was not funded by ganache, therefore you need to indicate ganache to fund more accounts to include that account. If you are using ganache-cli use this command to add 40 funded accounts:

ganache-cli -p 7545 -m “candy maple cake sugar pudding cream honey rich smooth crumble sweet treat” -a 40
  • -p or --port: Port number to listen on. Defaults to 8545.
  • -m or --mnemonic: Use a bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation.
  • -a or --accounts: Specify the number of accounts to generate at startup

If you are using the ganache with GUI do this to add 40 funded accounts:

5. Are there any specific version requirements for this project?

The problems works well with this versions

Truffle v5.0.8 (core: 5.0.8) Solidity - ^0.4.24 (solc-js) Node v10.7.0 Web3.js v1.0.0-beta.37

6. When I run each test file in a separate command it works:

truffle test ./test/flightSurety.js
truffle test ./test/oracles.js

But when I run the test files in a single command I get an error:

truffle test

Error:

Error: the tx doesn’t have the correct nonce. account has nonce of: 2 tx has nonce of: 3

There is apparently a problem when running the 2 test files at the same time: truffle test. This causes a problem with the nonces. It works fine and it is ACCEPTABLE to run each test file separately: truffle test ./test/flightSurety.js truffle test ./test/oracles.js

The IMPORTANT thing is that the test files pass all the test cases if they are run in separate commands like this:

truffle test ./test/flightSurety.js
truffle test ./test/oracles.js

7. It is not clear if for an airline needs to be funded to be able to register another airline. According to the instructions it looks like it just need to be registered but that could leave the system into a strange state. Is it correct?

It is expected that an airline is FUNDED to be able to register another airline

8. Trying to deploy FlightSuretyData, but geeting an error: “FlightSuretyData” — Invalid number of parameters for “undefined”. Got 0 expected 1!

If the constructor of a contract needs parameters, then you should manage this in the migration files. This is an example of how to pass as parameter to the FlightSuretyApp contract the address of the FlightSuretyData contract:

2_deploy_contracts.js

const FlightSuretyApp = artifacts.require("FlightSuretyApp");                       const FlightSuretyData = artifacts.require("FlightSuretyData");                       const fs = require('fs');                                               module.exports = function(deployer) {                                                   let firstAirline = '0xf17f52151EbEF6C7334FAD080c5704D77216b732';deployer.deploy(FlightSuretyData)
.then(() => {
return deployer.deploy(FlightSuretyApp, FlightSuretyData.address)
//OTHER CODE FROM THE BOILERPLATE
//OTHER CODE FROM THE BOILERPLATE

Boilerpleate

9. In my code, when I try to refund a passenger, I do it with a function

function withdraw() external requireFunds { uint256 value = flightSuretyData.getFunds(msg.sender); flightSuretyData.setFunds(msg.sender, 0); // TODO: msg.sender.transfer(value); emit FundsWithdrawed(msg.sender, value); }

With `msg.sender.transfer(value)`. But always fails. Why?

The withdraw function is normally implemented in the flightSuretyData contract

Because flightSuretyData is supposed to store the ether

Maybe that is the problem, flightSuretyData has the funds and flightSuretyApp don’t, then flightSuretyApp don’t not have enough funds to send to the passenger

Also remember that according to the architecture of contract upgradability, the contract that should store the Dapp's data is flightSuretyData. It also applies that flightSuretyData stores the funds because it is a central resource that is stored and managed and that is supposed to live as long as the system

10. I am getting this error when I use web3.eth.getBalance(passenger) in the truffle test file

Error: Invalid JSON RPC response: undefined
  • Make sure that you are using the last version of truffle or a version 5 or 5+ of truffle.
  • These versions of the dependecies work well
Truffle v5.0.9 (core: 5.0.9)
Node v10.7.0
Web3.js v1.0.0-beta.37

11. How can I test that the function for withdrawing the credit is working and the ether are going to the account of the passenger?

1)Get balance of the passenger previous to the transaction

2) Get gasUsed by the transaction and multiply it by the gas price, to get the amount of WEI consumed in the transaction

3) Get balance of the passenger after the transaction

4) Check that this is valid:

previousBalance < gasUsedWEI + afterBalance

12. For the requirement, “To participate, an airline should be funded with 10 ether”, to whom the fund would be transferred? And is it 10 ethers or 10 wei?

  • The funds are transferred to the Data contract. 1) You first send them to the App contract and 2) then the App contract sends them to the Data contract. Contracts can own ether.
  • To participate, an airline should be funded with 10 ether, NOT 10 wei.

13. Do you have an example of a good UI for the Dapp?

This is a great example for good UI for the Dapp:

This is an example of another great UI design by an Awesome Udacity Student, credits to him/her:

14. I have another question. In the smart contract, the airline struct is the following:

struct Airline {
bool isRegistered;
bool isFunded;
}

Which means that in the smart contract we are not saving information on the name of the airline. Is this something that I should do at the app level or should I modify the smart contract. I believe, it should be part of the smart contract.

You can improve the struct and add the properties that you find necessary for you application.

I think it is a good idea to store the name of the airline to identify it 👍

Also, you could store the address of the airline.

15. What does this test in the boilerplate mean?

it(`(multiparty) can allow access to setOperatingStatus() for Contract Owner account`,

It mentions “multiparty” and “owner contract”, how is suppose the “setOperatingStatus” function works? has to implement multiparty or not? if yes, how is this combined with the requirement that the account hast to be the contract owner? I am confused.

  • setOperatingStatus does not have to implement multiparty
  • setOperatingStatus works like this: The contract owner executes the function and passes to it the new value for the operational variable. No multiparty is needed
  • The function setOperatingStatus is already implemented in the boilerplate and there it no need to do anything else

17. I just want to check for the front end, are index.js, contract.js and index.html the only ones we need to update to make it work? I have not dealt with webpack before and this seems to be quite different from the earlier projects

To use the current Front End you just need to modify flightsurety.css, index.js, contract.js and index.html. I encourage you to create a really cool UI design 👍.

Answer from mentor Alvaro Andres Pinzon Cortes

Regarding webpack, they have few lessons about that. Please check Chapter 5: 5. Identity and Smart Contracts -> Lesson 3 -> Item 13: Creating the StarNotary (Version 2) (it uses webpack to install a quick prebuild app that they change to fit the starNotary)

Answer from student Stefanel S

18. I’m kind of unclear on what should be in the dapp UI? It looks like your FAQ has 5 “tasks” that can be initiated: create/register an airline, airline sends funds, passenger buys flight insurance, airline updates flight status, passenger claims insurance payout. What about the M of N voting with 50% of the registered airlines after the initial 4? I’m not sure where that goes.

It is not required to implement the voting for registering airlines after the initial 4 in the UI, but you can add it to your UI. That would be awesome 👏.

19. I am playing around with the oracle registration from within remix, but it seems to loop for unlimited gas for some reason. Do we need to make changes to that code or is it supposed to run straight out of the template code?

You need to do the following:

  • In server.js register the oracles
  • In server.js handle the OracleRequest events that are emitted when the function fetchFlightStatusfunction is called
  • In server.js submit the oracle response calling the function submitOracleResponsefunction in the contracts

20. how can I call “authorizeContract” to allow calls from the App contract to the Data one after deploying my contracts? Right now this call to “authorizeContract” is done from the test script, but what does happen when I deploy it normally?

You need to execute the function authorizeContract.

  • To do that you can create a simple website that uses web3 and metamask to execute the function
  • The other way is to use a tool like myetherwallet to call functions of a contract https://vintage.myetherwallet.com/#contracts

21. Is there a reference of the syntax we need to use to transfer funds from the App contract to the Data contract? Can’t seem to find any documentation so a link to the documentation would be helpful.

This first link shows an example of how to transfer funds from one contract to another by calling a payable function in the other contract https://ethereum.stackexchange.com/questions/9705/how-can-you-call-a-payable-function-in-another-contract-with-arguments-and-send/9722

In this second link, read the Creating Contracts via new section where they explain this topic in the documentation of solidity https://solidity.readthedocs.io/en/v0.5.6/control-structures.html#creating-contracts-via-new

22. I have a question: I am currently writing tests for my contract but in most cases I get an error when trying to make a transaction like ‘config.FlighSuretyApp.DoSomething()’. Even if the contract function contains no code at all. However calls like ‘config.FlighSuretyApp.DoSomething2.call()’ work. The error I get is something like: ‘Error: the tx doesn’t have the correct nonce. account has nonce of: ……’ But it may be true that the issue that I can’t make transactions has nothing to do with the error message since for this project I always get that kind of error message when the contract reverts. Help appreciated, Thanks!

I also had the same problem. My fix was to remove the HDWalletProvider from the provider of development network and just use the basic/raw config for a development network (address:http://localhost, port:8545}.

Answer from the awesome student Stefanel S

This nonce issue happens when something runs o ut of sync within your environmenmt. One thing to try is to perform a migration reset by running the command truffle migrate --reset

Answer from the awesome mentor Daniel A

The reason that config.FlighSuretyApp.DoSomething2.call()works is that when you do a call() you are not creating a new transaction, you are just reading from the blockchain. Meanwhile, when you run config.FlighSuretyApp.DoSomething() you are executing a function that changes the state of the contract (meaning, adding, deleting or changing information) which creates transactions

23. How to separate the code into multiple contracts, so that FlightSuretyData.sol is for data persistence and FlightSuretyApp.sol is for app logic and oracles code?

In the approach of contract upgradability we separate the Dapp in data and logic. The contract or contracts that represent the data SHOULD NOT have any logic or business rules, it should work just like a database.

All the parameters and logic that could change in the future due to business necessities, should be implemented FlightSuretyApp.

24. How can i implement a 50% consensus?

In the Udacity lecture “Multi-party Consensus” you can information about this. I suggest that you please try to watch all of the videos in that lecture. You can easily search for that lecture using the search tool in the classroom:

On the other hand, I am going to talk about how this multi-party concensus works.

What is multi-party concensus for?

  • It is used so that important decisions are made by the mayority of the stakeholders involved.
  • In the case of this project, it is used so that not anyone can register an airline and to verify that the airline that is being registered is not fake. If members think that the airline that is proposed to be registered is not good enough or if it not real, then they don’t vote in favor of registering it

How does multi-party concensus work?

  • It depends, every multi-party concensus can work differently.
  • In the case of this project, one way to make this multi-party concensus is that every registered and funded airline can vote if they want that the new airline gets registered. If the total of votes in favor is greater than the 50% of the number of register airlines, then the airline is register. If not the airline is rejected.
  • The total number of airlines registered also considers the airlines that are registered but not funded.
  • If an airline wants to vote, it needs to pay the initial funds.

What do I need to implement?

  • This is just a suggestion, you can make this concesus work in different ways and that would be fine if it meets the specifications in the review rubric.
  • You need to implement a functionality so that airlines can vote in favor or not to the registration of a new airline.
  • You need to implement a functionality that checks if a decisions was made and if the new airlines gets registered or rejected.

25. Does implementing a test in the oracles.js file is enough to pass the following specification in the review rubric? Upon startup, 20+ oracles are registered and their assigned indexes are persisted in memory

No, you need to implement this functionality of registering the 20 oracles in server.js file where the oracle server is implemented. When you run the command npm run server the 20 oracles need to be registered so that you can use the Dapp.

It is important to say that you also need to implement a test the to prove that upon startup, 20+ oracles are registered and their assigned indexes are persisted in memory

26. Regarding Airline Ante: Airline can be registered, but does not participate in contract until it submits funding of 10 ether; does this apply to also the firstAirline that gets registered when contract gets deployed ? Regards.

Yeah, it does, you also have to fund the first airline

27.Regarding the project requirenment: Multiparty Consensus:Only existing airline may register a new airline until there are at least four airlines registered. Is this referring that only the first registered airline airline1 (upon contract deployment) may register a new airline (until 4 of them are there) OR airline2 can register airline3 ..but only until 4 of them are there?(so basically any airline can register a new airline but only till 4 airlines max?)

Both interpretations are valid. What is important is that you clearly explain in the README how it works, so that the reviewer can understand. To make sure that everything is clear, these options are valid:

  • Only the first airline registered can register a new airline until there are 4 airlines in total, so the fifth must be registered with the multiparty consensus method.
  • Any airline registered can register a new airline until there are 4 airlines in total, so the fifth must be registered with the multiparty consensus method. So airline 2 can register airline 3, for example.

28. What are the data requirements for registering a flight? I’m thinking flight #, departure location, arrival location, departure and arrival times at a minimum. Does that sound right?

Regarding the question, it is is pretty much up to you, the only required thing I believe it is to ensure you can reference it later with some ID / Address

All metadata you mentioned is very relevant and pertinent to a flight, so it is great to add them

You need to balance the granularity of the data which you need and the value to store it

All data handled in a smart contract raises the gas cost, so you need to keep as short as possible maintaining the essential info that you really needs

Answer from the awesome mentor Daniel A.

29. In the flightSurety test, there is a Before Setup call to authorizeCaller. I can't see a stub for it in the Data Contract, so I'm wondering what it is supposed to do?

This method is used to authorize a FlightSuretyApp contract to interact with FlightSuretyData. You can use it to change which FlightSuretyApp is active.

But authorizeCaller is not required

30. How does the process of funding an airline work?

The process of funding an airline should be:

  1. The user calls the funding function in the APP contract and sends funds to the APP contract
  2. The APP contract sends the funds to the DATA contract by calling the funding function of the DATA contract
  3. The funds GO to the DATA contract account

31. Hello, do we have to migrate from 0.4.25 solidity version to v5 or can we keep in 0.4 ?

Yes, you can use the 0.4.25 solidity version, but it is important that you in the README.md file explain this and indicate what version of truffle and other dependencies are needed

32. Should we add new tests or just make sure the existing ones work well?

You need to add new tests

These are all the tests needed:

  • First airline is registered when contract is deployed.
  • Only existing airline may register a new airline until there are at least four airlines registered
  • Registration of fifth and subsequent airlines requires multi-party consensus of 50% of registered airlines
  • Airline can be registered, but does not participate in contract until it submits funding of 10 ether
  • Passengers may pay up to 1 ether for purchasing flight insurance.
  • If flight is delayed due to airline fault, passenger receives credit of 1.5X the amount they paid
  • Passenger can withdraw any funds owed to them as a result of receiving credit for insurance payout
  • Upon startup, 20+ oracles are registered and their assigned indexes are persisted in memory
  • Server will loop through all registered oracles, identify those oracles for which the OracleRequest event applies, and respond by calling into FlightSuretyApp contract with random status code of Unknown (0), On Time (10) or Late Airline (20), Late Weather (30), Late Technical (40), or Late Other (50)

33. Is there a breakdown or a list, step-by-step of what to do?

  1. Create a sequence diagram to understand the problem.
  2. Complete the FlightSuretyData.sol
  3. Complete the tests for FlightSuretyData
  4. Complete the FlightSuretyApp.sol
  5. Complete the tests for FlightSuretyApp
  6. Complete the server.js for the oracles
  7. Complete the tests in oracles.js
  8. Complete the requirements with Dapp

--

--

No responses yet