Skip to content

Commit c8eb5db

Browse files
Add files via upload
1 parent 2cb28fb commit c8eb5db

File tree

8 files changed

+241
-0
lines changed

8 files changed

+241
-0
lines changed

contracts/ConvertLib.sol

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pragma solidity ^0.4.4;
2+
3+
library ConvertLib{
4+
function convert(uint amount,uint conversionRate) returns (uint convertedAmount)
5+
{
6+
return amount * conversionRate;
7+
}
8+
}

contracts/Migrations.sol

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity ^0.4.4;
2+
3+
contract Migrations {
4+
address public owner;
5+
uint public last_completed_migration;
6+
7+
modifier restricted() {
8+
if (msg.sender == owner) _;
9+
}
10+
11+
function Migrations() {
12+
owner = msg.sender;
13+
}
14+
15+
function setCompleted(uint completed) restricted {
16+
last_completed_migration = completed;
17+
}
18+
19+
function upgrade(address new_address) restricted {
20+
Migrations upgraded = Migrations(new_address);
21+
upgraded.setCompleted(last_completed_migration);
22+
}
23+
}

contracts/auto.sol

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//Blockchain consortium for Automobile Sector –
2+
//Setup a private blockchain consortium with
3+
//minimum 2 parties (Automobile manufacturer and
4+
//OEM manufacturer). The Blockchain solution is
5+
//enabled to track the movement of automobile spare parts from
6+
//OEM warehouse to Automobile manufacturer facility where
7+
//they are also recorded in the blockchain while
8+
//each part is installed in a vehicle and the
9+
//information of vehicle is recorded in the ledger as well.
10+
function jo oem call karenge :
11+
1) created parts
12+
2 send parts to manufacturer(add to sent array)
13+
3
14+
function jo manufacturer call karega :
15+
1 pop from oem sent array
16+
2 check for defects
17+
3
18+
19+
20+
pragma solidity ^0.4.0;
21+
22+
contract SomeContract {
23+
24+
struct auto_industry {
25+
26+
uint typ;
27+
address add;
28+
29+
}
30+
31+
mapping(address => auto_industry ) addautoindustry;
32+
33+
function add_OEM() {
34+
35+
addautoindustry[msg.sender]=auto_industry(1,msg.sender);
36+
37+
}
38+
39+
modifier only_OEM() {
40+
41+
if (addautoindustry[msg.sender].typ==1){
42+
_;
43+
}
44+
45+
else {
46+
throw;
47+
}
48+
49+
}
50+
51+
function add_AUTO_MANU() {
52+
53+
addautoindustry[msg.sender]=auto_industry(2,msg.sender);
54+
55+
}
56+
57+
modifier only_AUTO_MANU() {
58+
59+
if (addautoindustry[msg.sender].typ==2){
60+
_;
61+
}
62+
63+
else {
64+
throw;
65+
}
66+
67+
}
68+
69+
uint[] public parts_quantity;
70+
71+
mapping (bytes32 => uint number) parts_mapping;
72+
73+
function addparts(bytes32 name, uint quantity) only_OEM {
74+
75+
parts_mapping[name]=quantity;
76+
77+
}
78+
79+
function display(bytes32 part_name) constant returns(uint[]) {
80+
81+
return parts_mapping[part_name].number;
82+
}
83+
84+
}
85+
86+
yeah man nice work !!!!!!!!!!!!!!!!!!
87+
cool terko kuch khana ha to khale bata de kitni der me vapas start karna hai??????
88+
11 seems perfect i am going byeee!!!!!!!!!!!!!! if you wanna talk text me
89+
yeah!!
90+
now listen!
91+
i will add that if already item exists then ill update the number
92+
its working fine.
93+
can you do one thing.the things i add can you put in array! if its required
94+
its working i just need to add the situation where overwrite happens ill just update those
95+
yeah!!!<------------
96+
do u want to take a break??
97+
i am gonna eat now so..ok bro
98+
half an hour or 1 hour
99+
tu bata
100+
cool!!! bye! bye! and copy the code just in case .. thanks

migrations/1_initial_migration.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var Migrations = artifacts.require("./Migrations.sol");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(Migrations);
5+
};

migrations/2_deploy_contracts.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var ConvertLib = artifacts.require("./ConvertLib.sol");
2+
var MetaCoin = artifacts.require("./MetaCoin.sol");
3+
4+
module.exports = function(deployer) {
5+
deployer.deploy(ConvertLib);
6+
deployer.link(ConvertLib, MetaCoin);
7+
deployer.deploy(MetaCoin);
8+
};

test/TestMetacoin.sol

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pragma solidity ^0.4.2;
2+
3+
import "truffle/Assert.sol";
4+
import "truffle/DeployedAddresses.sol";
5+
import "../contracts/MetaCoin.sol";
6+
7+
contract TestMetacoin {
8+
9+
function testInitialBalanceUsingDeployedContract() {
10+
MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin());
11+
12+
uint expected = 10000;
13+
14+
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
15+
}
16+
17+
function testInitialBalanceWithNewMetaCoin() {
18+
MetaCoin meta = new MetaCoin();
19+
20+
uint expected = 10000;
21+
22+
Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially");
23+
}
24+
25+
}

test/metacoin.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var MetaCoin = artifacts.require("./MetaCoin.sol");
2+
3+
contract('MetaCoin', function(accounts) {
4+
it("should put 10000 MetaCoin in the first account", function() {
5+
return MetaCoin.deployed().then(function(instance) {
6+
return instance.getBalance.call(accounts[0]);
7+
}).then(function(balance) {
8+
assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account");
9+
});
10+
});
11+
it("should call a function that depends on a linked library", function() {
12+
var meta;
13+
var metaCoinBalance;
14+
var metaCoinEthBalance;
15+
16+
return MetaCoin.deployed().then(function(instance) {
17+
meta = instance;
18+
return meta.getBalance.call(accounts[0]);
19+
}).then(function(outCoinBalance) {
20+
metaCoinBalance = outCoinBalance.toNumber();
21+
return meta.getBalanceInEth.call(accounts[0]);
22+
}).then(function(outCoinBalanceEth) {
23+
metaCoinEthBalance = outCoinBalanceEth.toNumber();
24+
}).then(function() {
25+
assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpected function, linkage may be broken");
26+
});
27+
});
28+
it("should send coin correctly", function() {
29+
var meta;
30+
31+
// Get initial balances of first and second account.
32+
var account_one = accounts[0];
33+
var account_two = accounts[1];
34+
35+
var account_one_starting_balance;
36+
var account_two_starting_balance;
37+
var account_one_ending_balance;
38+
var account_two_ending_balance;
39+
40+
var amount = 10;
41+
42+
return MetaCoin.deployed().then(function(instance) {
43+
meta = instance;
44+
return meta.getBalance.call(account_one);
45+
}).then(function(balance) {
46+
account_one_starting_balance = balance.toNumber();
47+
return meta.getBalance.call(account_two);
48+
}).then(function(balance) {
49+
account_two_starting_balance = balance.toNumber();
50+
return meta.sendCoin(account_two, amount, {from: account_one});
51+
}).then(function() {
52+
return meta.getBalance.call(account_one);
53+
}).then(function(balance) {
54+
account_one_ending_balance = balance.toNumber();
55+
return meta.getBalance.call(account_two);
56+
}).then(function(balance) {
57+
account_two_ending_balance = balance.toNumber();
58+
59+
assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender");
60+
assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver");
61+
});
62+
});
63+
});

truffle.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
networks: {
3+
development: {
4+
host: "localhost",
5+
port: 8545,
6+
network_id: "*" // Match any network id
7+
}
8+
}
9+
};

0 commit comments

Comments
 (0)